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
)
253 unsigned int bw
, ign
;
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
, &bw
, &ign
);
263 /* Translate real coordinates to coordinates relative to our
264 window. For our window, the upper left corner is 0, 0.
265 Since the upper left corner of the WM window is outside
266 our window, win_x and win_y will be negative:
268 ------------------ ---> x
270 | ----------------- v y
273 XTranslateCoordinates (FRAME_X_DISPLAY (f
),
275 /* From-window, to-window. */
276 FRAME_DISPLAY_INFO (f
)->root_window
,
279 /* From-position, to-position. */
280 real_x
, real_y
, &win_x
, &win_y
,
285 if (FRAME_X_WINDOW (f
) == FRAME_OUTER_WINDOW (f
))
292 XTranslateCoordinates (FRAME_X_DISPLAY (f
),
294 /* From-window, to-window. */
295 FRAME_DISPLAY_INFO (f
)->root_window
,
296 FRAME_OUTER_WINDOW (f
),
298 /* From-position, to-position. */
299 real_x
, real_y
, &outer_x
, &outer_y
,
305 had_errors
= x_had_errors_p (FRAME_X_DISPLAY (f
));
308 if (!had_errors
&& dpyinfo
->root_window
== f
->output_data
.x
->parent_desc
)
310 /* Try _NET_FRAME_EXTENTS if our parent is the root window. */
311 rc
= XGetWindowProperty (dpy
, win
, dpyinfo
->Xatom_net_frame_extents
,
312 0, max_len
, False
, target_type
,
313 &actual_type
, &actual_format
, &actual_size
,
314 &bytes_remaining
, &tmp_data
);
316 if (rc
== Success
&& actual_type
== target_type
&& !x_had_errors_p (dpy
)
317 && actual_size
== 4 && actual_format
== 32)
319 long *fe
= (long *)tmp_data
;
327 if (tmp_data
) XFree (tmp_data
);
334 if (had_errors
) return;
336 if (x_pixels_diff
) *x_pixels_diff
= -win_x
;
337 if (y_pixels_diff
) *y_pixels_diff
= -win_y
;
339 if (left_offset_x
) *left_offset_x
= -outer_x
;
340 if (top_offset_y
) *top_offset_y
= -outer_y
;
342 if (xptr
) *xptr
= real_x
;
343 if (yptr
) *yptr
= real_y
;
345 if (right_offset_x
|| bottom_offset_y
)
348 unsigned int ign
, fw
, fh
;
351 XGetGeometry (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
352 &rootw
, &xy_ign
, &xy_ign
, &fw
, &fh
, &ign
, &ign
);
353 if (right_offset_x
) *right_offset_x
= ow
- fw
+ outer_x
;
354 if (bottom_offset_y
) *bottom_offset_y
= oh
- fh
+ outer_y
;
358 /* Store the screen positions of frame F into XPTR and YPTR.
359 These are the positions of the containing window manager window,
360 not Emacs's own window. */
363 x_real_positions (struct frame
*f
, int *xptr
, int *yptr
)
365 x_real_pos_and_offsets (f
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, xptr
, yptr
,
370 /* Get the mouse position in frame relative coordinates. */
373 x_relative_mouse_position (struct frame
*f
, int *x
, int *y
)
375 Window root
, dummy_window
;
378 eassert (FRAME_X_P (f
));
382 XQueryPointer (FRAME_X_DISPLAY (f
),
383 DefaultRootWindow (FRAME_X_DISPLAY (f
)),
385 /* The root window which contains the pointer. */
388 /* Window pointer is on, not used */
391 /* The position on that root window. */
394 /* x/y in dummy_window coordinates, not used. */
397 /* Modifier keys and pointer buttons, about which
399 (unsigned int *) &dummy
);
401 XTranslateCoordinates (FRAME_X_DISPLAY (f
),
403 /* From-window, to-window. */
404 FRAME_DISPLAY_INFO (f
)->root_window
,
407 /* From-position, to-position. */
416 /* Gamma-correct COLOR on frame F. */
419 gamma_correct (struct frame
*f
, XColor
*color
)
423 color
->red
= pow (color
->red
/ 65535.0, f
->gamma
) * 65535.0 + 0.5;
424 color
->green
= pow (color
->green
/ 65535.0, f
->gamma
) * 65535.0 + 0.5;
425 color
->blue
= pow (color
->blue
/ 65535.0, f
->gamma
) * 65535.0 + 0.5;
430 /* Decide if color named COLOR_NAME is valid for use on frame F. If
431 so, return the RGB values in COLOR. If ALLOC_P,
432 allocate the color. Value is false if COLOR_NAME is invalid, or
433 no color could be allocated. */
436 x_defined_color (struct frame
*f
, const char *color_name
,
437 XColor
*color
, bool alloc_p
)
439 bool success_p
= false;
440 Colormap cmap
= FRAME_X_COLORMAP (f
);
444 success_p
= xg_check_special_colors (f
, color_name
, color
);
447 success_p
= x_parse_color (f
, color_name
, color
) != 0;
448 if (success_p
&& alloc_p
)
449 success_p
= x_alloc_nearest_color (f
, cmap
, color
);
456 /* Return the pixel color value for color COLOR_NAME on frame F. If F
457 is a monochrome frame, return MONO_COLOR regardless of what ARG says.
458 Signal an error if color can't be allocated. */
461 x_decode_color (struct frame
*f
, Lisp_Object color_name
, int mono_color
)
465 CHECK_STRING (color_name
);
467 #if false /* Don't do this. It's wrong when we're not using the default
468 colormap, it makes freeing difficult, and it's probably not
469 an important optimization. */
470 if (strcmp (SDATA (color_name
), "black") == 0)
471 return BLACK_PIX_DEFAULT (f
);
472 else if (strcmp (SDATA (color_name
), "white") == 0)
473 return WHITE_PIX_DEFAULT (f
);
476 /* Return MONO_COLOR for monochrome frames. */
477 if (FRAME_DISPLAY_INFO (f
)->n_planes
== 1)
480 /* x_defined_color is responsible for coping with failures
481 by looking for a near-miss. */
482 if (x_defined_color (f
, SSDATA (color_name
), &cdef
, true))
485 signal_error ("Undefined color", color_name
);
490 /* Change the `wait-for-wm' frame parameter of frame F. OLD_VALUE is
491 the previous value of that parameter, NEW_VALUE is the new value.
492 See also the comment of wait_for_wm in struct x_output. */
495 x_set_wait_for_wm (struct frame
*f
, Lisp_Object new_value
, Lisp_Object old_value
)
497 f
->output_data
.x
->wait_for_wm
= !NILP (new_value
);
501 x_set_tool_bar_position (struct frame
*f
,
502 Lisp_Object new_value
,
503 Lisp_Object old_value
)
505 Lisp_Object choice
= list4 (Qleft
, Qright
, Qtop
, Qbottom
);
507 if (!NILP (Fmemq (new_value
, choice
)))
510 if (!EQ (new_value
, old_value
))
512 xg_change_toolbar_position (f
, new_value
);
513 fset_tool_bar_position (f
, new_value
);
516 if (!EQ (new_value
, Qtop
))
517 error ("The only supported tool bar position is top");
521 wrong_choice (choice
, new_value
);
526 /* Set icon from FILE for frame F. By using GTK functions the icon
527 may be any format that GdkPixbuf knows about, i.e. not just bitmaps. */
530 xg_set_icon (struct frame
*f
, Lisp_Object file
)
535 found
= x_find_image_file (file
);
541 char *filename
= SSDATA (ENCODE_FILE (found
));
544 pixbuf
= gdk_pixbuf_new_from_file (filename
, &err
);
548 gtk_window_set_icon (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)),
550 g_object_unref (pixbuf
);
564 xg_set_icon_from_xpm_data (struct frame
*f
, const char **data
)
566 GdkPixbuf
*pixbuf
= gdk_pixbuf_new_from_xpm_data (data
);
571 gtk_window_set_icon (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)), pixbuf
);
572 g_object_unref (pixbuf
);
578 /* Functions called only from `x_set_frame_param'
579 to set individual parameters.
581 If FRAME_X_WINDOW (f) is 0,
582 the frame is being created and its X-window does not exist yet.
583 In that case, just record the parameter's new value
584 in the standard place; do not attempt to change the window. */
587 x_set_foreground_color (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
589 struct x_output
*x
= f
->output_data
.x
;
590 unsigned long fg
, old_fg
;
592 fg
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
593 old_fg
= FRAME_FOREGROUND_PIXEL (f
);
594 FRAME_FOREGROUND_PIXEL (f
) = fg
;
596 if (FRAME_X_WINDOW (f
) != 0)
598 Display
*dpy
= FRAME_X_DISPLAY (f
);
601 XSetForeground (dpy
, x
->normal_gc
, fg
);
602 XSetBackground (dpy
, x
->reverse_gc
, fg
);
604 if (x
->cursor_pixel
== old_fg
)
606 unload_color (f
, x
->cursor_pixel
);
607 x
->cursor_pixel
= x_copy_color (f
, fg
);
608 XSetBackground (dpy
, x
->cursor_gc
, x
->cursor_pixel
);
613 update_face_from_frame_parameter (f
, Qforeground_color
, arg
);
615 if (FRAME_VISIBLE_P (f
))
619 unload_color (f
, old_fg
);
623 x_set_background_color (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
625 struct x_output
*x
= f
->output_data
.x
;
628 bg
= x_decode_color (f
, arg
, WHITE_PIX_DEFAULT (f
));
629 unload_color (f
, FRAME_BACKGROUND_PIXEL (f
));
630 FRAME_BACKGROUND_PIXEL (f
) = bg
;
632 if (FRAME_X_WINDOW (f
) != 0)
634 Display
*dpy
= FRAME_X_DISPLAY (f
);
637 XSetBackground (dpy
, x
->normal_gc
, bg
);
638 XSetForeground (dpy
, x
->reverse_gc
, bg
);
639 XSetWindowBackground (dpy
, FRAME_X_WINDOW (f
), bg
);
640 XSetForeground (dpy
, x
->cursor_gc
, bg
);
643 xg_set_background_color (f
, bg
);
646 #ifndef USE_TOOLKIT_SCROLL_BARS /* Turns out to be annoying with
647 toolkit scroll bars. */
650 for (bar
= FRAME_SCROLL_BARS (f
);
652 bar
= XSCROLL_BAR (bar
)->next
)
654 Window window
= XSCROLL_BAR (bar
)->x_window
;
655 XSetWindowBackground (dpy
, window
, bg
);
658 #endif /* USE_TOOLKIT_SCROLL_BARS */
661 update_face_from_frame_parameter (f
, Qbackground_color
, arg
);
663 if (FRAME_VISIBLE_P (f
))
668 /* This array must stay in sync with the mouse_cursor_types array below! */
671 mouse_cursor_nontext
,
672 mouse_cursor_hourglass
,
675 mouse_cursor_horizontal_drag
,
676 mouse_cursor_vertical_drag
,
680 struct mouse_cursor_types
{
681 /* Printable name for error messages (optional). */
684 /* Lisp variable controlling the cursor shape. */
685 /* FIXME: A couple of these variables are defined in the C code but
686 are not actually accessible from Lisp. They should probably be
687 made accessible or removed. */
688 Lisp_Object
*shape_var_ptr
;
690 /* The default shape. */
694 /* This array must stay in sync with enum mouse_cursor above! */
695 static const struct mouse_cursor_types mouse_cursor_types
[] = {
696 { "text", &Vx_pointer_shape
, XC_xterm
},
697 { "nontext", &Vx_nontext_pointer_shape
, XC_left_ptr
},
698 { "hourglass", &Vx_hourglass_pointer_shape
, XC_watch
},
699 { "modeline", &Vx_mode_pointer_shape
, XC_xterm
},
700 { NULL
, &Vx_sensitive_text_pointer_shape
, XC_hand2
},
701 { NULL
, &Vx_window_horizontal_drag_shape
, XC_sb_h_double_arrow
},
702 { NULL
, &Vx_window_vertical_drag_shape
, XC_sb_v_double_arrow
},
705 struct mouse_cursor_data
{
706 /* Last index for which XCreateFontCursor has been called, and thus
707 the last index for which x_request_serial[] is valid. */
708 int last_cursor_create_request
;
710 /* Last index for which an X error event was received in response to
711 attempting to create the cursor. */
714 /* Cursor numbers chosen. */
715 unsigned int cursor_num
[mouse_cursor_max
];
717 /* Allocated Cursor values, or zero for failed attempts. */
718 Cursor cursor
[mouse_cursor_max
];
720 /* X serial numbers for the first request sent by XCreateFontCursor.
721 Note that there may be more than one request sent. */
722 unsigned long x_request_serial
[mouse_cursor_max
];
724 /* If an error has been received, a pointer to where the current
725 error-message text is stored. */
730 x_set_mouse_color_handler (Display
*dpy
, XErrorEvent
*event
,
731 char *error_string
, void *data
)
733 struct mouse_cursor_data
*cursor_data
= data
;
736 cursor_data
->error_cursor
= -1;
737 cursor_data
->error_string
= error_string
;
738 for (i
= 0; i
< cursor_data
->last_cursor_create_request
; i
++)
740 if (event
->serial
>= cursor_data
->x_request_serial
[i
])
741 cursor_data
->error_cursor
= i
;
743 if (cursor_data
->error_cursor
>= 0)
744 /* If we failed to allocate it, don't try to free it. */
745 cursor_data
->cursor
[cursor_data
->error_cursor
] = 0;
749 x_set_mouse_color (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
751 struct x_output
*x
= f
->output_data
.x
;
752 Display
*dpy
= FRAME_X_DISPLAY (f
);
753 struct mouse_cursor_data cursor_data
= { -1, -1 };
754 unsigned long pixel
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
755 unsigned long mask_color
= FRAME_BACKGROUND_PIXEL (f
);
758 /* Don't let pointers be invisible. */
759 if (mask_color
== pixel
)
761 x_free_colors (f
, &pixel
, 1);
762 pixel
= x_copy_color (f
, FRAME_FOREGROUND_PIXEL (f
));
765 unload_color (f
, x
->mouse_pixel
);
766 x
->mouse_pixel
= pixel
;
768 for (i
= 0; i
< mouse_cursor_max
; i
++)
770 Lisp_Object shape_var
= *mouse_cursor_types
[i
].shape_var_ptr
;
771 if (!NILP (shape_var
))
773 CHECK_TYPE_RANGED_INTEGER (unsigned, shape_var
);
774 cursor_data
.cursor_num
[i
] = XINT (shape_var
);
777 cursor_data
.cursor_num
[i
] = mouse_cursor_types
[i
].default_shape
;
782 /* It's not okay to crash if the user selects a screwy cursor. */
783 x_catch_errors_with_handler (dpy
, x_set_mouse_color_handler
, &cursor_data
);
785 for (i
= 0; i
< mouse_cursor_max
; i
++)
787 cursor_data
.x_request_serial
[i
] = XNextRequest (dpy
);
788 cursor_data
.last_cursor_create_request
= i
;
789 cursor_data
.cursor
[i
] = XCreateFontCursor (dpy
,
790 cursor_data
.cursor_num
[i
]);
793 /* Now sync up and process all received errors from cursor
795 if (x_had_errors_p (dpy
))
797 const char *bad_cursor_name
= NULL
;
798 /* Bounded by X_ERROR_MESSAGE_SIZE in xterm.c. */
799 size_t message_length
= strlen (cursor_data
.error_string
);
800 char *xmessage
= alloca (1 + message_length
);
801 memcpy (xmessage
, cursor_data
.error_string
, message_length
);
805 /* Free any successfully created cursors. */
806 for (i
= 0; i
< mouse_cursor_max
; i
++)
807 if (cursor_data
.cursor
[i
] != 0)
808 XFreeCursor (dpy
, cursor_data
.cursor
[i
]);
810 /* This should only be able to fail if the server's serial
811 number tracking is broken. */
812 if (cursor_data
.error_cursor
>= 0)
813 bad_cursor_name
= mouse_cursor_types
[cursor_data
.error_cursor
].name
;
815 error ("bad %s pointer cursor: %s", bad_cursor_name
, xmessage
);
817 error ("can't set cursor shape: %s", xmessage
);
820 x_uncatch_errors_after_check ();
823 XColor colors
[2]; /* 0=foreground, 1=background */
825 colors
[0].pixel
= x
->mouse_pixel
;
826 colors
[1].pixel
= mask_color
;
827 x_query_colors (f
, colors
, 2);
829 for (i
= 0; i
< mouse_cursor_max
; i
++)
830 XRecolorCursor (dpy
, cursor_data
.cursor
[i
], &colors
[0], &colors
[1]);
833 if (FRAME_X_WINDOW (f
) != 0)
835 f
->output_data
.x
->current_cursor
= cursor_data
.cursor
[mouse_cursor_text
];
836 XDefineCursor (dpy
, FRAME_X_WINDOW (f
),
837 f
->output_data
.x
->current_cursor
);
840 #define INSTALL_CURSOR(FIELD, SHORT_INDEX) \
841 eassert (x->FIELD != cursor_data.cursor[mouse_cursor_ ## SHORT_INDEX]); \
843 XFreeCursor (dpy, x->FIELD); \
844 x->FIELD = cursor_data.cursor[mouse_cursor_ ## SHORT_INDEX];
846 INSTALL_CURSOR (text_cursor
, text
);
847 INSTALL_CURSOR (nontext_cursor
, nontext
);
848 INSTALL_CURSOR (hourglass_cursor
, hourglass
);
849 INSTALL_CURSOR (modeline_cursor
, mode
);
850 INSTALL_CURSOR (hand_cursor
, hand
);
851 INSTALL_CURSOR (horizontal_drag_cursor
, horizontal_drag
);
852 INSTALL_CURSOR (vertical_drag_cursor
, vertical_drag
);
854 #undef INSTALL_CURSOR
859 update_face_from_frame_parameter (f
, Qmouse_color
, arg
);
863 x_set_cursor_color (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
865 unsigned long fore_pixel
, pixel
;
866 bool fore_pixel_allocated_p
= false, pixel_allocated_p
= false;
867 struct x_output
*x
= f
->output_data
.x
;
869 if (!NILP (Vx_cursor_fore_pixel
))
871 fore_pixel
= x_decode_color (f
, Vx_cursor_fore_pixel
,
872 WHITE_PIX_DEFAULT (f
));
873 fore_pixel_allocated_p
= true;
876 fore_pixel
= FRAME_BACKGROUND_PIXEL (f
);
878 pixel
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
879 pixel_allocated_p
= true;
881 /* Make sure that the cursor color differs from the background color. */
882 if (pixel
== FRAME_BACKGROUND_PIXEL (f
))
884 if (pixel_allocated_p
)
886 x_free_colors (f
, &pixel
, 1);
887 pixel_allocated_p
= false;
890 pixel
= x
->mouse_pixel
;
891 if (pixel
== fore_pixel
)
893 if (fore_pixel_allocated_p
)
895 x_free_colors (f
, &fore_pixel
, 1);
896 fore_pixel_allocated_p
= false;
898 fore_pixel
= FRAME_BACKGROUND_PIXEL (f
);
902 unload_color (f
, x
->cursor_foreground_pixel
);
903 if (!fore_pixel_allocated_p
)
904 fore_pixel
= x_copy_color (f
, fore_pixel
);
905 x
->cursor_foreground_pixel
= fore_pixel
;
907 unload_color (f
, x
->cursor_pixel
);
908 if (!pixel_allocated_p
)
909 pixel
= x_copy_color (f
, pixel
);
910 x
->cursor_pixel
= pixel
;
912 if (FRAME_X_WINDOW (f
) != 0)
915 XSetBackground (FRAME_X_DISPLAY (f
), x
->cursor_gc
, x
->cursor_pixel
);
916 XSetForeground (FRAME_X_DISPLAY (f
), x
->cursor_gc
, fore_pixel
);
919 if (FRAME_VISIBLE_P (f
))
921 x_update_cursor (f
, false);
922 x_update_cursor (f
, true);
926 update_face_from_frame_parameter (f
, Qcursor_color
, arg
);
929 /* Set the border-color of frame F to pixel value PIX.
930 Note that this does not fully take effect if done before
931 F has an x-window. */
934 x_set_border_pixel (struct frame
*f
, int pix
)
936 unload_color (f
, f
->output_data
.x
->border_pixel
);
937 f
->output_data
.x
->border_pixel
= pix
;
939 if (FRAME_X_WINDOW (f
) != 0 && f
->border_width
> 0)
942 XSetWindowBorder (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), pix
);
945 if (FRAME_VISIBLE_P (f
))
950 /* Set the border-color of frame F to value described by ARG.
951 ARG can be a string naming a color.
952 The border-color is used for the border that is drawn by the X server.
953 Note that this does not fully take effect if done before
954 F has an x-window; it must be redone when the window is created.
956 Note: this is done in two routines because of the way X10 works.
958 Note: under X11, this is normally the province of the window manager,
959 and so emacs's border colors may be overridden. */
962 x_set_border_color (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
967 pix
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
968 x_set_border_pixel (f
, pix
);
969 update_face_from_frame_parameter (f
, Qborder_color
, arg
);
974 x_set_cursor_type (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
976 set_frame_cursor_types (f
, arg
);
980 x_set_icon_type (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
986 if (STRINGP (oldval
) && EQ (Fstring_equal (oldval
, arg
), Qt
))
989 else if (!STRINGP (oldval
) && EQ (oldval
, Qnil
) == EQ (arg
, Qnil
))
994 result
= x_text_icon (f
,
995 SSDATA ((!NILP (f
->icon_name
)
999 result
= x_bitmap_icon (f
, arg
);
1004 error ("No icon window available");
1007 XFlush (FRAME_X_DISPLAY (f
));
1012 x_set_icon_name (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1018 if (STRINGP (oldval
) && EQ (Fstring_equal (oldval
, arg
), Qt
))
1021 else if (!NILP (arg
) || NILP (oldval
))
1024 fset_icon_name (f
, arg
);
1026 if (f
->output_data
.x
->icon_bitmap
!= 0)
1031 result
= x_text_icon (f
,
1032 SSDATA ((!NILP (f
->icon_name
)
1041 error ("No icon window available");
1044 XFlush (FRAME_X_DISPLAY (f
));
1050 x_set_menu_bar_lines (struct frame
*f
, Lisp_Object value
, Lisp_Object oldval
)
1053 #if ! defined (USE_X_TOOLKIT) && ! defined (USE_GTK)
1054 int olines
= FRAME_MENU_BAR_LINES (f
);
1057 /* Right now, menu bars don't work properly in minibuf-only frames;
1058 most of the commands try to apply themselves to the minibuffer
1059 frame itself, and get an error because you can't switch buffers
1060 in or split the minibuffer window. */
1061 if (FRAME_MINIBUF_ONLY_P (f
))
1064 if (TYPE_RANGED_INTEGERP (int, value
))
1065 nlines
= XINT (value
);
1069 /* Make sure we redisplay all windows in this frame. */
1072 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
1073 FRAME_MENU_BAR_LINES (f
) = 0;
1074 FRAME_MENU_BAR_HEIGHT (f
) = 0;
1077 FRAME_EXTERNAL_MENU_BAR (f
) = 1;
1078 if (FRAME_X_P (f
) && f
->output_data
.x
->menubar_widget
== 0)
1079 /* Make sure next redisplay shows the menu bar. */
1080 XWINDOW (FRAME_SELECTED_WINDOW (f
))->update_mode_line
= true;
1084 if (FRAME_EXTERNAL_MENU_BAR (f
) == 1)
1085 free_frame_menubar (f
);
1086 FRAME_EXTERNAL_MENU_BAR (f
) = 0;
1088 f
->output_data
.x
->menubar_widget
= 0;
1090 #else /* not USE_X_TOOLKIT && not USE_GTK */
1091 FRAME_MENU_BAR_LINES (f
) = nlines
;
1092 FRAME_MENU_BAR_HEIGHT (f
) = nlines
* FRAME_LINE_HEIGHT (f
);
1093 adjust_frame_size (f
, -1, -1, 2, true, Qx_set_menu_bar_lines
);
1094 if (FRAME_X_WINDOW (f
))
1095 x_clear_under_internal_border (f
);
1097 /* If the menu bar height gets changed, the internal border below
1098 the top margin has to be cleared. Also, if the menu bar gets
1099 larger, the area for the added lines has to be cleared except for
1100 the first menu bar line that is to be drawn later. */
1101 if (nlines
!= olines
)
1103 int height
= FRAME_INTERNAL_BORDER_WIDTH (f
);
1104 int width
= FRAME_PIXEL_WIDTH (f
);
1107 /* height can be zero here. */
1108 if (FRAME_X_WINDOW (f
) && height
> 0 && width
> 0)
1110 y
= FRAME_TOP_MARGIN_HEIGHT (f
);
1113 x_clear_area (f
, 0, y
, width
, height
);
1117 if (nlines
> 1 && nlines
> olines
)
1119 y
= (olines
== 0 ? 1 : olines
) * FRAME_LINE_HEIGHT (f
);
1120 height
= nlines
* FRAME_LINE_HEIGHT (f
) - y
;
1123 x_clear_area (f
, 0, y
, width
, height
);
1127 if (nlines
== 0 && WINDOWP (f
->menu_bar_window
))
1128 clear_glyph_matrix (XWINDOW (f
->menu_bar_window
)->current_matrix
);
1130 #endif /* not USE_X_TOOLKIT && not USE_GTK */
1131 adjust_frame_glyphs (f
);
1132 run_window_configuration_change_hook (f
);
1136 /* Set the number of lines used for the tool bar of frame F to VALUE.
1137 VALUE not an integer, or < 0 means set the lines to zero. OLDVAL
1138 is the old number of tool bar lines. This function changes the
1139 height of all windows on frame F to match the new tool bar height.
1140 The frame's height doesn't change. */
1143 x_set_tool_bar_lines (struct frame
*f
, Lisp_Object value
, Lisp_Object oldval
)
1147 /* Treat tool bars like menu bars. */
1148 if (FRAME_MINIBUF_ONLY_P (f
))
1151 /* Use VALUE only if an int >= 0. */
1152 if (RANGED_INTEGERP (0, value
, INT_MAX
))
1153 nlines
= XFASTINT (value
);
1157 x_change_tool_bar_height (f
, nlines
* FRAME_LINE_HEIGHT (f
));
1161 /* Set the pixel height of the tool bar of frame F to HEIGHT. */
1163 x_change_tool_bar_height (struct frame
*f
, int height
)
1166 FRAME_TOOL_BAR_LINES (f
) = 0;
1167 FRAME_TOOL_BAR_HEIGHT (f
) = 0;
1170 FRAME_EXTERNAL_TOOL_BAR (f
) = true;
1171 if (FRAME_X_P (f
) && f
->output_data
.x
->toolbar_widget
== 0)
1172 /* Make sure next redisplay shows the tool bar. */
1173 XWINDOW (FRAME_SELECTED_WINDOW (f
))->update_mode_line
= true;
1174 update_frame_tool_bar (f
);
1178 if (FRAME_EXTERNAL_TOOL_BAR (f
))
1179 free_frame_tool_bar (f
);
1180 FRAME_EXTERNAL_TOOL_BAR (f
) = false;
1182 #else /* !USE_GTK */
1183 int unit
= FRAME_LINE_HEIGHT (f
);
1184 int old_height
= FRAME_TOOL_BAR_HEIGHT (f
);
1185 int lines
= (height
+ unit
- 1) / unit
;
1186 Lisp_Object fullscreen
;
1188 /* Make sure we redisplay all windows in this frame. */
1191 /* Recalculate tool bar and frame text sizes. */
1192 FRAME_TOOL_BAR_HEIGHT (f
) = height
;
1193 FRAME_TOOL_BAR_LINES (f
) = lines
;
1194 /* Store the `tool-bar-lines' and `height' frame parameters. */
1195 store_frame_param (f
, Qtool_bar_lines
, make_number (lines
));
1196 store_frame_param (f
, Qheight
, make_number (FRAME_LINES (f
)));
1198 /* We also have to make sure that the internal border at the top of
1199 the frame, below the menu bar or tool bar, is redrawn when the
1200 tool bar disappears. This is so because the internal border is
1201 below the tool bar if one is displayed, but is below the menu bar
1202 if there isn't a tool bar. The tool bar draws into the area
1203 below the menu bar. */
1204 if (FRAME_X_WINDOW (f
) && FRAME_TOOL_BAR_HEIGHT (f
) == 0)
1207 clear_current_matrices (f
);
1210 if ((height
< old_height
) && WINDOWP (f
->tool_bar_window
))
1211 clear_glyph_matrix (XWINDOW (f
->tool_bar_window
)->current_matrix
);
1213 /* Recalculate toolbar height. */
1214 f
->n_tool_bar_rows
= 0;
1216 && (!f
->after_make_frame
1217 || NILP (frame_inhibit_implied_resize
)
1218 || (CONSP (frame_inhibit_implied_resize
)
1219 && NILP (Fmemq (Qtool_bar_lines
, frame_inhibit_implied_resize
)))))
1220 f
->tool_bar_redisplayed
= f
->tool_bar_resized
= false;
1222 adjust_frame_size (f
, -1, -1,
1223 ((!f
->tool_bar_resized
1224 && (NILP (fullscreen
=
1225 get_frame_param (f
, Qfullscreen
))
1226 || EQ (fullscreen
, Qfullwidth
))) ? 1
1227 : (old_height
== 0 || height
== 0) ? 2
1229 false, Qtool_bar_lines
);
1231 f
->tool_bar_resized
= f
->tool_bar_redisplayed
;
1233 /* adjust_frame_size might not have done anything, garbage frame
1235 adjust_frame_glyphs (f
);
1236 SET_FRAME_GARBAGED (f
);
1237 if (FRAME_X_WINDOW (f
))
1238 x_clear_under_internal_border (f
);
1240 #endif /* USE_GTK */
1245 x_set_internal_border_width (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1249 CHECK_TYPE_RANGED_INTEGER (int, arg
);
1250 border
= max (XINT (arg
), 0);
1252 if (border
!= FRAME_INTERNAL_BORDER_WIDTH (f
))
1254 FRAME_INTERNAL_BORDER_WIDTH (f
) = border
;
1256 #ifdef USE_X_TOOLKIT
1257 if (FRAME_X_OUTPUT (f
)->edit_widget
)
1258 widget_store_internal_border (FRAME_X_OUTPUT (f
)->edit_widget
);
1261 if (FRAME_X_WINDOW (f
) != 0)
1263 adjust_frame_size (f
, -1, -1, 3, false, Qinternal_border_width
);
1266 xg_clear_under_internal_border (f
);
1268 x_clear_under_internal_border (f
);
1276 /* Set the foreground color for scroll bars on frame F to VALUE.
1277 VALUE should be a string, a color name. If it isn't a string or
1278 isn't a valid color name, do nothing. OLDVAL is the old value of
1279 the frame parameter. */
1282 x_set_scroll_bar_foreground (struct frame
*f
, Lisp_Object value
, Lisp_Object oldval
)
1284 unsigned long pixel
;
1286 if (STRINGP (value
))
1287 pixel
= x_decode_color (f
, value
, BLACK_PIX_DEFAULT (f
));
1291 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
1292 unload_color (f
, f
->output_data
.x
->scroll_bar_foreground_pixel
);
1294 f
->output_data
.x
->scroll_bar_foreground_pixel
= pixel
;
1295 if (FRAME_X_WINDOW (f
) && FRAME_VISIBLE_P (f
))
1297 /* Remove all scroll bars because they have wrong colors. */
1298 if (FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
)
1299 (*FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
) (f
);
1300 if (FRAME_TERMINAL (f
)->judge_scroll_bars_hook
)
1301 (*FRAME_TERMINAL (f
)->judge_scroll_bars_hook
) (f
);
1303 update_face_from_frame_parameter (f
, Qscroll_bar_foreground
, value
);
1309 /* Set the background color for scroll bars on frame F to VALUE VALUE
1310 should be a string, a color name. If it isn't a string or isn't a
1311 valid color name, do nothing. OLDVAL is the old value of the frame
1315 x_set_scroll_bar_background (struct frame
*f
, Lisp_Object value
, Lisp_Object oldval
)
1317 unsigned long pixel
;
1319 if (STRINGP (value
))
1320 pixel
= x_decode_color (f
, value
, WHITE_PIX_DEFAULT (f
));
1324 if (f
->output_data
.x
->scroll_bar_background_pixel
!= -1)
1325 unload_color (f
, f
->output_data
.x
->scroll_bar_background_pixel
);
1327 #if defined (USE_LUCID) && defined (USE_TOOLKIT_SCROLL_BARS)
1328 /* Scrollbar shadow colors. */
1329 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
!= -1)
1331 unload_color (f
, f
->output_data
.x
->scroll_bar_top_shadow_pixel
);
1332 f
->output_data
.x
->scroll_bar_top_shadow_pixel
= -1;
1334 if (f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
!= -1)
1336 unload_color (f
, f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
);
1337 f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
= -1;
1339 #endif /* USE_LUCID && USE_TOOLKIT_SCROLL_BARS */
1341 f
->output_data
.x
->scroll_bar_background_pixel
= pixel
;
1342 if (FRAME_X_WINDOW (f
) && FRAME_VISIBLE_P (f
))
1344 /* Remove all scroll bars because they have wrong colors. */
1345 if (FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
)
1346 (*FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
) (f
);
1347 if (FRAME_TERMINAL (f
)->judge_scroll_bars_hook
)
1348 (*FRAME_TERMINAL (f
)->judge_scroll_bars_hook
) (f
);
1350 update_face_from_frame_parameter (f
, Qscroll_bar_background
, value
);
1356 /* Encode Lisp string STRING as a text in a format appropriate for
1357 XICCC (X Inter Client Communication Conventions).
1359 If STRING contains only ASCII characters, do no conversion and
1360 return the string data of STRING. Otherwise, encode the text by
1361 CODING_SYSTEM, and return a newly allocated memory area which
1362 should be freed by `xfree' by a caller.
1364 Store the byte length of resulting text in *TEXT_BYTES.
1366 If the text contains only ASCII and Latin-1, store true in *STRING_P,
1367 which means that the `encoding' of the result can be `STRING'.
1368 Otherwise store false in *STRINGP, which means that the `encoding' of
1369 the result should be `COMPOUND_TEXT'. */
1371 static unsigned char *
1372 x_encode_text (Lisp_Object string
, Lisp_Object coding_system
,
1373 ptrdiff_t *text_bytes
, bool *stringp
, bool *freep
)
1375 int result
= string_xstring_p (string
);
1376 struct coding_system coding
;
1380 /* No multibyte character in OBJ. We need not encode it. */
1381 *text_bytes
= SBYTES (string
);
1384 return SDATA (string
);
1387 setup_coding_system (coding_system
, &coding
);
1388 coding
.mode
|= (CODING_MODE_SAFE_ENCODING
| CODING_MODE_LAST_BLOCK
);
1389 /* We suppress producing escape sequences for composition. */
1390 coding
.common_flags
&= ~CODING_ANNOTATION_MASK
;
1391 coding
.destination
= xnmalloc (SCHARS (string
), 2);
1392 coding
.dst_bytes
= SCHARS (string
) * 2;
1393 encode_coding_object (&coding
, string
, 0, 0,
1394 SCHARS (string
), SBYTES (string
), Qnil
);
1395 *text_bytes
= coding
.produced
;
1396 *stringp
= (result
== 1 || !EQ (coding_system
, Qcompound_text
));
1398 return coding
.destination
;
1402 /* Set the WM name to NAME for frame F. Also set the icon name.
1403 If the frame already has an icon name, use that, otherwise set the
1404 icon name to NAME. */
1407 x_set_name_internal (struct frame
*f
, Lisp_Object name
)
1409 if (FRAME_X_WINDOW (f
))
1413 XTextProperty text
, icon
;
1416 bool do_free_icon_value
= false, do_free_text_value
= false;
1417 Lisp_Object coding_system
;
1418 Lisp_Object encoded_name
;
1419 Lisp_Object encoded_icon_name
;
1421 /* As ENCODE_UTF_8 may cause GC and relocation of string data,
1422 we use it before x_encode_text that may return string data. */
1423 encoded_name
= ENCODE_UTF_8 (name
);
1425 coding_system
= Qcompound_text
;
1426 /* Note: Encoding strategy
1428 We encode NAME by compound-text and use "COMPOUND-TEXT" in
1429 text.encoding. But, there are non-internationalized window
1430 managers which don't support that encoding. So, if NAME
1431 contains only ASCII and 8859-1 characters, encode it by
1432 iso-latin-1, and use "STRING" in text.encoding hoping that
1433 such window managers at least analyze this format correctly,
1434 i.e. treat 8-bit bytes as 8859-1 characters.
1436 We may also be able to use "UTF8_STRING" in text.encoding
1437 in the future which can encode all Unicode characters.
1438 But, for the moment, there's no way to know that the
1439 current window manager supports it or not.
1441 Either way, we also set the _NET_WM_NAME and _NET_WM_ICON_NAME
1442 properties. Per the EWMH specification, those two properties
1443 are always UTF8_STRING. This matches what gtk_window_set_title()
1444 does in the USE_GTK case. */
1445 text
.value
= x_encode_text (name
, coding_system
, &bytes
,
1446 &stringp
, &do_free_text_value
);
1447 text
.encoding
= (stringp
? XA_STRING
1448 : FRAME_DISPLAY_INFO (f
)->Xatom_COMPOUND_TEXT
);
1450 text
.nitems
= bytes
;
1452 if (!STRINGP (f
->icon_name
))
1455 encoded_icon_name
= encoded_name
;
1459 /* See the above comment "Note: Encoding strategy". */
1460 icon
.value
= x_encode_text (f
->icon_name
, coding_system
, &bytes
,
1461 &stringp
, &do_free_icon_value
);
1462 icon
.encoding
= (stringp
? XA_STRING
1463 : FRAME_DISPLAY_INFO (f
)->Xatom_COMPOUND_TEXT
);
1465 icon
.nitems
= bytes
;
1467 encoded_icon_name
= ENCODE_UTF_8 (f
->icon_name
);
1471 gtk_window_set_title (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)),
1472 SSDATA (encoded_name
));
1473 #else /* not USE_GTK */
1474 XSetWMName (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
), &text
);
1475 XChangeProperty (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
1476 FRAME_DISPLAY_INFO (f
)->Xatom_net_wm_name
,
1477 FRAME_DISPLAY_INFO (f
)->Xatom_UTF8_STRING
,
1479 SDATA (encoded_name
),
1480 SBYTES (encoded_name
));
1481 #endif /* not USE_GTK */
1483 XSetWMIconName (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
), &icon
);
1484 XChangeProperty (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
1485 FRAME_DISPLAY_INFO (f
)->Xatom_net_wm_icon_name
,
1486 FRAME_DISPLAY_INFO (f
)->Xatom_UTF8_STRING
,
1488 SDATA (encoded_icon_name
),
1489 SBYTES (encoded_icon_name
));
1491 if (do_free_icon_value
)
1493 if (do_free_text_value
)
1500 /* Change the name of frame F to NAME. If NAME is nil, set F's name to
1503 If EXPLICIT is true, that indicates that lisp code is setting the
1504 name; if NAME is a string, set F's name to NAME and set
1505 F->explicit_name; if NAME is Qnil, then clear F->explicit_name.
1507 If EXPLICIT is false, that indicates that Emacs redisplay code is
1508 suggesting a new name, which lisp code should override; if
1509 F->explicit_name is set, ignore the new name; otherwise, set it. */
1512 x_set_name (struct frame
*f
, Lisp_Object name
, bool explicit)
1514 /* Make sure that requests from lisp code override requests from
1515 Emacs redisplay code. */
1518 /* If we're switching from explicit to implicit, we had better
1519 update the mode lines and thereby update the title. */
1520 if (f
->explicit_name
&& NILP (name
))
1521 update_mode_lines
= 37;
1523 f
->explicit_name
= ! NILP (name
);
1525 else if (f
->explicit_name
)
1528 /* If NAME is nil, set the name to the x_id_name. */
1531 /* Check for no change needed in this very common case
1532 before we do any consing. */
1533 if (!strcmp (FRAME_DISPLAY_INFO (f
)->x_id_name
,
1536 name
= build_string (FRAME_DISPLAY_INFO (f
)->x_id_name
);
1539 CHECK_STRING (name
);
1541 /* Don't change the name if it's already NAME. */
1542 if (! NILP (Fstring_equal (name
, f
->name
)))
1545 fset_name (f
, name
);
1547 /* For setting the frame title, the title parameter should override
1548 the name parameter. */
1549 if (! NILP (f
->title
))
1552 x_set_name_internal (f
, name
);
1555 /* This function should be called when the user's lisp code has
1556 specified a name for the frame; the name will override any set by the
1559 x_explicitly_set_name (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1561 x_set_name (f
, arg
, true);
1564 /* This function should be called by Emacs redisplay code to set the
1565 name; names set this way will never override names set by the user's
1568 x_implicitly_set_name (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1570 x_set_name (f
, arg
, false);
1573 /* Change the title of frame F to NAME.
1574 If NAME is nil, use the frame name as the title. */
1577 x_set_title (struct frame
*f
, Lisp_Object name
, Lisp_Object old_name
)
1579 /* Don't change the title if it's already NAME. */
1580 if (EQ (name
, f
->title
))
1583 update_mode_lines
= 38;
1585 fset_title (f
, name
);
1590 CHECK_STRING (name
);
1592 x_set_name_internal (f
, name
);
1596 x_set_scroll_bar_default_width (struct frame
*f
)
1598 int unit
= FRAME_COLUMN_WIDTH (f
);
1599 #ifdef USE_TOOLKIT_SCROLL_BARS
1601 int minw
= xg_get_default_scrollbar_width ();
1605 /* A minimum width of 14 doesn't look good for toolkit scroll bars. */
1606 FRAME_CONFIG_SCROLL_BAR_COLS (f
) = (minw
+ unit
- 1) / unit
;
1607 FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) = minw
;
1609 /* The width of a non-toolkit scrollbar is 14 pixels. */
1610 FRAME_CONFIG_SCROLL_BAR_COLS (f
) = (14 + unit
- 1) / unit
;
1611 FRAME_CONFIG_SCROLL_BAR_WIDTH (f
)
1612 = FRAME_CONFIG_SCROLL_BAR_COLS (f
) * unit
;
1617 x_set_scroll_bar_default_height (struct frame
*f
)
1619 int height
= FRAME_LINE_HEIGHT (f
);
1620 #ifdef USE_TOOLKIT_SCROLL_BARS
1622 int min_height
= xg_get_default_scrollbar_height ();
1624 int min_height
= 16;
1626 /* A minimum height of 14 doesn't look good for toolkit scroll bars. */
1627 FRAME_CONFIG_SCROLL_BAR_HEIGHT (f
) = min_height
;
1628 FRAME_CONFIG_SCROLL_BAR_LINES (f
) = (min_height
+ height
- 1) / height
;
1630 /* The height of a non-toolkit scrollbar is 14 pixels. */
1631 FRAME_CONFIG_SCROLL_BAR_LINES (f
) = (14 + height
- 1) / height
;
1633 /* Use all of that space (aside from required margins) for the
1635 FRAME_CONFIG_SCROLL_BAR_HEIGHT (f
) = 14;
1640 /* Record in frame F the specified or default value according to ALIST
1641 of the parameter named PROP (a Lisp symbol). If no value is
1642 specified for PROP, look for an X default for XPROP on the frame
1643 named NAME. If that is not found either, use the value DEFLT. */
1646 x_default_scroll_bar_color_parameter (struct frame
*f
,
1647 Lisp_Object alist
, Lisp_Object prop
,
1648 const char *xprop
, const char *xclass
,
1651 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
1654 tem
= x_get_arg (dpyinfo
, alist
, prop
, xprop
, xclass
, RES_TYPE_STRING
);
1655 if (EQ (tem
, Qunbound
))
1657 #ifdef USE_TOOLKIT_SCROLL_BARS
1659 /* See if an X resource for the scroll bar color has been
1661 AUTO_STRING (foreground
, "foreground");
1662 AUTO_STRING (background
, "foreground");
1663 AUTO_STRING (verticalScrollBar
, "verticalScrollBar");
1664 tem
= (display_x_get_resource
1665 (dpyinfo
, foreground_p
? foreground
: background
,
1666 empty_unibyte_string
,
1668 empty_unibyte_string
));
1671 /* If nothing has been specified, scroll bars will use a
1672 toolkit-dependent default. Because these defaults are
1673 difficult to get at without actually creating a scroll
1674 bar, use nil to indicate that no color has been
1679 #else /* not USE_TOOLKIT_SCROLL_BARS */
1683 #endif /* not USE_TOOLKIT_SCROLL_BARS */
1686 AUTO_FRAME_ARG (arg
, prop
, tem
);
1687 x_set_frame_parameters (f
, arg
);
1694 #ifdef USE_X_TOOLKIT
1696 /* If the WM_PROTOCOLS property does not already contain WM_TAKE_FOCUS,
1697 WM_DELETE_WINDOW, and WM_SAVE_YOURSELF, then add them. (They may
1698 already be present because of the toolkit (Motif adds some of them,
1699 for example, but Xt doesn't). */
1702 hack_wm_protocols (struct frame
*f
, Widget widget
)
1704 Display
*dpy
= XtDisplay (widget
);
1705 Window w
= XtWindow (widget
);
1706 bool need_delete
= true;
1707 bool need_focus
= true;
1708 bool need_save
= true;
1713 unsigned char *catoms
;
1715 unsigned long nitems
= 0;
1716 unsigned long bytes_after
;
1718 if ((XGetWindowProperty (dpy
, w
,
1719 FRAME_DISPLAY_INFO (f
)->Xatom_wm_protocols
,
1720 0, 100, False
, XA_ATOM
,
1721 &type
, &format
, &nitems
, &bytes_after
,
1724 && format
== 32 && type
== XA_ATOM
)
1726 Atom
*atoms
= (Atom
*) catoms
;
1731 == FRAME_DISPLAY_INFO (f
)->Xatom_wm_delete_window
)
1732 need_delete
= false;
1733 else if (atoms
[nitems
]
1734 == FRAME_DISPLAY_INFO (f
)->Xatom_wm_take_focus
)
1736 else if (atoms
[nitems
]
1737 == FRAME_DISPLAY_INFO (f
)->Xatom_wm_save_yourself
)
1748 props
[count
++] = FRAME_DISPLAY_INFO (f
)->Xatom_wm_delete_window
;
1750 props
[count
++] = FRAME_DISPLAY_INFO (f
)->Xatom_wm_take_focus
;
1752 props
[count
++] = FRAME_DISPLAY_INFO (f
)->Xatom_wm_save_yourself
;
1754 XChangeProperty (dpy
, w
, FRAME_DISPLAY_INFO (f
)->Xatom_wm_protocols
,
1755 XA_ATOM
, 32, PropModeAppend
,
1756 (unsigned char *) props
, count
);
1764 /* Support routines for XIC (X Input Context). */
1768 static XFontSet
xic_create_xfontset (struct frame
*);
1769 static XIMStyle
best_xim_style (XIMStyles
*);
1772 /* Supported XIM styles, ordered by preference. */
1774 static const XIMStyle supported_xim_styles
[] =
1776 XIMPreeditPosition
| XIMStatusArea
,
1777 XIMPreeditPosition
| XIMStatusNothing
,
1778 XIMPreeditPosition
| XIMStatusNone
,
1779 XIMPreeditNothing
| XIMStatusArea
,
1780 XIMPreeditNothing
| XIMStatusNothing
,
1781 XIMPreeditNothing
| XIMStatusNone
,
1782 XIMPreeditNone
| XIMStatusArea
,
1783 XIMPreeditNone
| XIMStatusNothing
,
1784 XIMPreeditNone
| XIMStatusNone
,
1789 #if defined HAVE_X_WINDOWS && defined USE_X_TOOLKIT
1790 /* Create an X fontset on frame F with base font name BASE_FONTNAME. */
1792 static const char xic_default_fontset
[] = "-*-*-*-r-normal--14-*-*-*-*-*-*-*";
1794 /* Create an Xt fontset spec from the name of a base font.
1795 If `motif' is True use the Motif syntax. */
1797 xic_create_fontsetname (const char *base_fontname
, bool motif
)
1799 const char *sep
= motif
? ";" : ",";
1803 /* Make a fontset name from the base font name. */
1804 if (xic_default_fontset
== base_fontname
)
1806 /* There is no base font name, use the default. */
1807 fontsetname
= xmalloc (strlen (base_fontname
) + 2);
1808 z
= stpcpy (fontsetname
, base_fontname
);
1812 /* Make a fontset name from the base font name.
1813 The font set will be made of the following elements:
1815 - the base font where the charset spec is replaced by -*-*.
1816 - the same but with the family also replaced with -*-*-. */
1817 const char *p
= base_fontname
;
1820 for (i
= 0; *p
; p
++)
1824 /* As the font name doesn't conform to XLFD, we can't
1825 modify it to generalize it to allcs and allfamilies.
1826 Use the specified font plus the default. */
1827 fontsetname
= xmalloc (strlen (base_fontname
)
1828 + strlen (xic_default_fontset
) + 3);
1829 z
= stpcpy (fontsetname
, base_fontname
);
1830 z
= stpcpy (z
, sep
);
1831 z
= stpcpy (z
, xic_default_fontset
);
1836 const char *p1
= NULL
, *p2
= NULL
, *p3
= NULL
;
1837 char *font_allcs
= NULL
;
1838 char *font_allfamilies
= NULL
;
1839 char *font_all
= NULL
;
1840 const char *allcs
= "*-*-*-*-*-*-*";
1841 const char *allfamilies
= "-*-*-";
1842 const char *all
= "*-*-*-*-";
1845 for (i
= 0, p
= base_fontname
; i
< 8; p
++)
1858 /* If base_fontname specifies ADSTYLE, make it a
1862 ptrdiff_t diff
= (p2
- p3
) - 2;
1864 base
= alloca (strlen (base_fontname
) + 1);
1865 memcpy (base
, base_fontname
, p3
- base_fontname
);
1866 base
[p3
- base_fontname
] = '*';
1867 base
[(p3
- base_fontname
) + 1] = '-';
1868 strcpy (base
+ (p3
- base_fontname
) + 2, p2
);
1869 p
= base
+ (p
- base_fontname
) - diff
;
1870 p1
= base
+ (p1
- base_fontname
);
1871 p2
= base
+ (p2
- base_fontname
) - diff
;
1872 base_fontname
= base
;
1875 /* Build the font spec that matches all charsets. */
1876 len
= p
- base_fontname
+ strlen (allcs
) + 1;
1877 font_allcs
= alloca (len
);
1878 memcpy (font_allcs
, base_fontname
, p
- base_fontname
);
1879 strcpy (font_allcs
+ (p
- base_fontname
), allcs
);
1881 /* Build the font spec that matches all families and
1883 len
= p
- p1
+ strlen (allcs
) + strlen (allfamilies
) + 1;
1884 font_allfamilies
= alloca (len
);
1885 strcpy (font_allfamilies
, allfamilies
);
1886 memcpy (font_allfamilies
+ strlen (allfamilies
), p1
, p
- p1
);
1887 strcpy (font_allfamilies
+ strlen (allfamilies
) + (p
- p1
), allcs
);
1889 /* Build the font spec that matches all. */
1890 len
= p
- p2
+ strlen (allcs
) + strlen (all
) + strlen (allfamilies
) + 1;
1891 font_all
= alloca (len
);
1892 z
= stpcpy (font_all
, allfamilies
);
1893 z
= stpcpy (z
, all
);
1894 memcpy (z
, p2
, p
- p2
);
1895 strcpy (z
+ (p
- p2
), allcs
);
1897 /* Build the actual font set name. */
1898 len
= strlen (base_fontname
) + strlen (font_allcs
)
1899 + strlen (font_allfamilies
) + strlen (font_all
) + 5;
1900 fontsetname
= xmalloc (len
);
1901 z
= stpcpy (fontsetname
, base_fontname
);
1902 z
= stpcpy (z
, sep
);
1903 z
= stpcpy (z
, font_allcs
);
1904 z
= stpcpy (z
, sep
);
1905 z
= stpcpy (z
, font_allfamilies
);
1906 z
= stpcpy (z
, sep
);
1907 z
= stpcpy (z
, font_all
);
1914 #endif /* HAVE_X_WINDOWS && USE_X_TOOLKIT */
1916 #ifdef DEBUG_XIC_FONTSET
1918 print_fontset_result (XFontSet xfs
, char *name
, char **missing_list
,
1922 fprintf (stderr
, "XIC Fontset created: %s\n", name
);
1925 fprintf (stderr
, "XIC Fontset failed: %s\n", name
);
1926 while (missing_count
-- > 0)
1928 fprintf (stderr
, " missing: %s\n", *missing_list
);
1937 xic_create_xfontset (struct frame
*f
)
1939 XFontSet xfs
= NULL
;
1940 struct font
*font
= FRAME_FONT (f
);
1941 int pixel_size
= font
->pixel_size
;
1942 Lisp_Object rest
, frame
;
1944 /* See if there is another frame already using same fontset. */
1945 FOR_EACH_FRAME (rest
, frame
)
1947 struct frame
*cf
= XFRAME (frame
);
1949 if (cf
!= f
&& FRAME_LIVE_P (f
) && FRAME_X_P (cf
)
1950 && FRAME_DISPLAY_INFO (cf
) == FRAME_DISPLAY_INFO (f
)
1952 && FRAME_FONT (f
)->pixel_size
== pixel_size
)
1954 xfs
= FRAME_XIC_FONTSET (cf
);
1962 char **missing_list
;
1965 const char *xlfd_format
= "-*-*-medium-r-normal--%d-*-*-*-*-*";
1967 sprintf (buf
, xlfd_format
, pixel_size
);
1968 missing_list
= NULL
;
1969 xfs
= XCreateFontSet (FRAME_X_DISPLAY (f
), buf
,
1970 &missing_list
, &missing_count
, &def_string
);
1971 #ifdef DEBUG_XIC_FONTSET
1972 print_fontset_result (xfs
, buf
, missing_list
, missing_count
);
1975 XFreeStringList (missing_list
);
1978 /* List of pixel sizes most likely available. Find one that
1979 is closest to pixel_size. */
1980 int sizes
[] = {0, 8, 10, 11, 12, 14, 17, 18, 20, 24, 26, 34, 0};
1981 int *smaller
, *larger
;
1983 for (smaller
= sizes
; smaller
[1]; smaller
++)
1984 if (smaller
[1] >= pixel_size
)
1986 larger
= smaller
+ 1;
1987 if (*larger
== pixel_size
)
1989 while (*smaller
|| *larger
)
1994 this_size
= *smaller
--;
1995 else if (! *smaller
)
1996 this_size
= *larger
++;
1997 else if (pixel_size
- *smaller
< *larger
- pixel_size
)
1998 this_size
= *smaller
--;
2000 this_size
= *larger
++;
2001 sprintf (buf
, xlfd_format
, this_size
);
2002 missing_list
= NULL
;
2003 xfs
= XCreateFontSet (FRAME_X_DISPLAY (f
), buf
,
2004 &missing_list
, &missing_count
, &def_string
);
2005 #ifdef DEBUG_XIC_FONTSET
2006 print_fontset_result (xfs
, buf
, missing_list
, missing_count
);
2009 XFreeStringList (missing_list
);
2016 const char *last_resort
= "-*-*-*-r-normal--*-*-*-*-*-*";
2018 missing_list
= NULL
;
2019 xfs
= XCreateFontSet (FRAME_X_DISPLAY (f
), last_resort
,
2020 &missing_list
, &missing_count
, &def_string
);
2021 #ifdef DEBUG_XIC_FONTSET
2022 print_fontset_result (xfs
, last_resort
, missing_list
, missing_count
);
2025 XFreeStringList (missing_list
);
2033 /* Free the X fontset of frame F if it is the last frame using it. */
2036 xic_free_xfontset (struct frame
*f
)
2038 Lisp_Object rest
, frame
;
2039 bool shared_p
= false;
2041 if (!FRAME_XIC_FONTSET (f
))
2044 /* See if there is another frame sharing the same fontset. */
2045 FOR_EACH_FRAME (rest
, frame
)
2047 struct frame
*cf
= XFRAME (frame
);
2048 if (cf
!= f
&& FRAME_LIVE_P (f
) && FRAME_X_P (cf
)
2049 && FRAME_DISPLAY_INFO (cf
) == FRAME_DISPLAY_INFO (f
)
2050 && FRAME_XIC_FONTSET (cf
) == FRAME_XIC_FONTSET (f
))
2058 /* The fontset is not used anymore. It is safe to free it. */
2059 XFreeFontSet (FRAME_X_DISPLAY (f
), FRAME_XIC_FONTSET (f
));
2061 FRAME_XIC_FONTSET (f
) = NULL
;
2065 /* Value is the best input style, given user preferences USER (already
2066 checked to be supported by Emacs), and styles supported by the
2067 input method XIM. */
2070 best_xim_style (XIMStyles
*xim
)
2073 int nr_supported
= ARRAYELTS (supported_xim_styles
);
2075 for (i
= 0; i
< nr_supported
; ++i
)
2076 for (j
= 0; j
< xim
->count_styles
; ++j
)
2077 if (supported_xim_styles
[i
] == xim
->supported_styles
[j
])
2078 return supported_xim_styles
[i
];
2080 /* Return the default style. */
2081 return XIMPreeditNothing
| XIMStatusNothing
;
2084 /* Create XIC for frame F. */
2087 create_frame_xic (struct frame
*f
)
2091 XFontSet xfs
= NULL
;
2092 XVaNestedList status_attr
= NULL
;
2093 XVaNestedList preedit_attr
= NULL
;
2101 xim
= FRAME_X_XIM (f
);
2105 /* Determine XIC style. */
2106 xic_style
= best_xim_style (FRAME_X_XIM_STYLES (f
));
2108 /* Create X fontset. */
2109 if (xic_style
& (XIMPreeditPosition
| XIMStatusArea
))
2111 xfs
= xic_create_xfontset (f
);
2115 FRAME_XIC_FONTSET (f
) = xfs
;
2118 if (xic_style
& XIMPreeditPosition
)
2120 spot
.x
= 0; spot
.y
= 1;
2121 preedit_attr
= XVaCreateNestedList (0,
2124 FRAME_FOREGROUND_PIXEL (f
),
2126 FRAME_BACKGROUND_PIXEL (f
),
2127 (xic_style
& XIMPreeditPosition
2137 if (xic_style
& XIMStatusArea
)
2139 s_area
.x
= 0; s_area
.y
= 0; s_area
.width
= 1; s_area
.height
= 1;
2140 status_attr
= XVaCreateNestedList (0,
2146 FRAME_FOREGROUND_PIXEL (f
),
2148 FRAME_BACKGROUND_PIXEL (f
),
2155 if (preedit_attr
&& status_attr
)
2156 xic
= XCreateIC (xim
,
2157 XNInputStyle
, xic_style
,
2158 XNClientWindow
, FRAME_X_WINDOW (f
),
2159 XNFocusWindow
, FRAME_X_WINDOW (f
),
2160 XNStatusAttributes
, status_attr
,
2161 XNPreeditAttributes
, preedit_attr
,
2163 else if (preedit_attr
)
2164 xic
= XCreateIC (xim
,
2165 XNInputStyle
, xic_style
,
2166 XNClientWindow
, FRAME_X_WINDOW (f
),
2167 XNFocusWindow
, FRAME_X_WINDOW (f
),
2168 XNPreeditAttributes
, preedit_attr
,
2170 else if (status_attr
)
2171 xic
= XCreateIC (xim
,
2172 XNInputStyle
, xic_style
,
2173 XNClientWindow
, FRAME_X_WINDOW (f
),
2174 XNFocusWindow
, FRAME_X_WINDOW (f
),
2175 XNStatusAttributes
, status_attr
,
2178 xic
= XCreateIC (xim
,
2179 XNInputStyle
, xic_style
,
2180 XNClientWindow
, FRAME_X_WINDOW (f
),
2181 XNFocusWindow
, FRAME_X_WINDOW (f
),
2187 FRAME_XIC (f
) = xic
;
2188 FRAME_XIC_STYLE (f
) = xic_style
;
2189 xfs
= NULL
; /* Don't free below. */
2197 XFree (preedit_attr
);
2200 XFree (status_attr
);
2204 /* Destroy XIC and free XIC fontset of frame F, if any. */
2207 free_frame_xic (struct frame
*f
)
2209 if (FRAME_XIC (f
) == NULL
)
2212 XDestroyIC (FRAME_XIC (f
));
2213 xic_free_xfontset (f
);
2215 FRAME_XIC (f
) = NULL
;
2219 /* Place preedit area for XIC of window W's frame to specified
2220 pixel position X/Y. X and Y are relative to window W. */
2223 xic_set_preeditarea (struct window
*w
, int x
, int y
)
2225 struct frame
*f
= XFRAME (w
->frame
);
2229 spot
.x
= WINDOW_TO_FRAME_PIXEL_X (w
, x
) + WINDOW_LEFT_FRINGE_WIDTH (w
);
2230 spot
.y
= WINDOW_TO_FRAME_PIXEL_Y (w
, y
) + FONT_BASE (FRAME_FONT (f
));
2231 attr
= XVaCreateNestedList (0, XNSpotLocation
, &spot
, NULL
);
2232 XSetICValues (FRAME_XIC (f
), XNPreeditAttributes
, attr
, NULL
);
2237 /* Place status area for XIC in bottom right corner of frame F.. */
2240 xic_set_statusarea (struct frame
*f
)
2242 XIC xic
= FRAME_XIC (f
);
2247 /* Negotiate geometry of status area. If input method has existing
2248 status area, use its current size. */
2249 area
.x
= area
.y
= area
.width
= area
.height
= 0;
2250 attr
= XVaCreateNestedList (0, XNAreaNeeded
, &area
, NULL
);
2251 XSetICValues (xic
, XNStatusAttributes
, attr
, NULL
);
2254 attr
= XVaCreateNestedList (0, XNAreaNeeded
, &needed
, NULL
);
2255 XGetICValues (xic
, XNStatusAttributes
, attr
, NULL
);
2258 if (needed
->width
== 0) /* Use XNArea instead of XNAreaNeeded */
2260 attr
= XVaCreateNestedList (0, XNArea
, &needed
, NULL
);
2261 XGetICValues (xic
, XNStatusAttributes
, attr
, NULL
);
2265 area
.width
= needed
->width
;
2266 area
.height
= needed
->height
;
2267 area
.x
= FRAME_PIXEL_WIDTH (f
) - area
.width
- FRAME_INTERNAL_BORDER_WIDTH (f
);
2268 area
.y
= (FRAME_PIXEL_HEIGHT (f
) - area
.height
2269 - FRAME_MENUBAR_HEIGHT (f
)
2270 - FRAME_TOOLBAR_TOP_HEIGHT (f
)
2271 - FRAME_INTERNAL_BORDER_WIDTH (f
));
2274 attr
= XVaCreateNestedList (0, XNArea
, &area
, NULL
);
2275 XSetICValues (xic
, XNStatusAttributes
, attr
, NULL
);
2280 /* Set X fontset for XIC of frame F, using base font name
2281 BASE_FONTNAME. Called when a new Emacs fontset is chosen. */
2284 xic_set_xfontset (struct frame
*f
, const char *base_fontname
)
2289 xic_free_xfontset (f
);
2291 xfs
= xic_create_xfontset (f
);
2293 attr
= XVaCreateNestedList (0, XNFontSet
, xfs
, NULL
);
2294 if (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
)
2295 XSetICValues (FRAME_XIC (f
), XNPreeditAttributes
, attr
, NULL
);
2296 if (FRAME_XIC_STYLE (f
) & XIMStatusArea
)
2297 XSetICValues (FRAME_XIC (f
), XNStatusAttributes
, attr
, NULL
);
2300 FRAME_XIC_FONTSET (f
) = xfs
;
2303 #endif /* HAVE_X_I18N */
2307 #ifdef USE_X_TOOLKIT
2309 /* Create and set up the X widget for frame F. */
2312 x_window (struct frame
*f
, long window_prompting
)
2314 XClassHint class_hints
;
2315 XSetWindowAttributes attributes
;
2316 unsigned long attribute_mask
;
2317 Widget shell_widget
;
2319 Widget frame_widget
;
2325 /* Use the resource name as the top-level widget name
2326 for looking up resources. Make a non-Lisp copy
2327 for the window manager, so GC relocation won't bother it.
2329 Elsewhere we specify the window name for the window manager. */
2330 f
->namebuf
= xlispstrdup (Vx_resource_name
);
2333 XtSetArg (al
[ac
], XtNallowShellResize
, 1); ac
++;
2334 XtSetArg (al
[ac
], XtNinput
, 1); ac
++;
2335 XtSetArg (al
[ac
], XtNmappedWhenManaged
, 0); ac
++;
2336 XtSetArg (al
[ac
], XtNborderWidth
, f
->border_width
); ac
++;
2337 XtSetArg (al
[ac
], XtNvisual
, FRAME_X_VISUAL (f
)); ac
++;
2338 XtSetArg (al
[ac
], XtNdepth
, FRAME_DISPLAY_INFO (f
)->n_planes
); ac
++;
2339 XtSetArg (al
[ac
], XtNcolormap
, FRAME_X_COLORMAP (f
)); ac
++;
2340 shell_widget
= XtAppCreateShell (f
->namebuf
, EMACS_CLASS
,
2341 applicationShellWidgetClass
,
2342 FRAME_X_DISPLAY (f
), al
, ac
);
2344 f
->output_data
.x
->widget
= shell_widget
;
2345 /* maybe_set_screen_title_format (shell_widget); */
2347 pane_widget
= lw_create_widget ("main", "pane", widget_id_tick
++,
2348 NULL
, shell_widget
, False
,
2349 NULL
, NULL
, NULL
, NULL
);
2352 XtSetArg (al
[ac
], XtNvisual
, FRAME_X_VISUAL (f
)); ac
++;
2353 XtSetArg (al
[ac
], XtNdepth
, FRAME_DISPLAY_INFO (f
)->n_planes
); ac
++;
2354 XtSetArg (al
[ac
], XtNcolormap
, FRAME_X_COLORMAP (f
)); ac
++;
2355 XtSetArg (al
[ac
], XtNborderWidth
, 0); ac
++;
2356 XtSetValues (pane_widget
, al
, ac
);
2357 f
->output_data
.x
->column_widget
= pane_widget
;
2359 /* mappedWhenManaged to false tells to the paned window to not map/unmap
2360 the emacs screen when changing menubar. This reduces flickering. */
2363 XtSetArg (al
[ac
], XtNmappedWhenManaged
, 0); ac
++;
2364 XtSetArg (al
[ac
], XtNshowGrip
, 0); ac
++;
2365 XtSetArg (al
[ac
], XtNallowResize
, 1); ac
++;
2366 XtSetArg (al
[ac
], XtNresizeToPreferred
, 1); ac
++;
2367 XtSetArg (al
[ac
], XtNemacsFrame
, f
); ac
++;
2368 XtSetArg (al
[ac
], XtNvisual
, FRAME_X_VISUAL (f
)); ac
++;
2369 XtSetArg (al
[ac
], XtNdepth
, FRAME_DISPLAY_INFO (f
)->n_planes
); ac
++;
2370 XtSetArg (al
[ac
], XtNcolormap
, FRAME_X_COLORMAP (f
)); ac
++;
2371 XtSetArg (al
[ac
], XtNborderWidth
, 0); ac
++;
2372 frame_widget
= XtCreateWidget (f
->namebuf
, emacsFrameClass
, pane_widget
,
2375 f
->output_data
.x
->edit_widget
= frame_widget
;
2377 XtManageChild (frame_widget
);
2379 /* Do some needed geometry management. */
2383 int extra_borders
= 0;
2385 = (f
->output_data
.x
->menubar_widget
2386 ? (f
->output_data
.x
->menubar_widget
->core
.height
2387 + f
->output_data
.x
->menubar_widget
->core
.border_width
)
2390 #if false /* Experimentally, we now get the right results
2391 for -geometry -0-0 without this. 24 Aug 96, rms. */
2392 if (FRAME_EXTERNAL_MENU_BAR (f
))
2395 XtVaGetValues (pane_widget
, XtNinternalBorderWidth
, &ibw
, NULL
);
2396 menubar_size
+= ibw
;
2400 FRAME_MENUBAR_HEIGHT (f
) = menubar_size
;
2403 /* Motif seems to need this amount added to the sizes
2404 specified for the shell widget. The Athena/Lucid widgets don't.
2405 Both conclusions reached experimentally. -- rms. */
2406 XtVaGetValues (f
->output_data
.x
->edit_widget
, XtNinternalBorderWidth
,
2407 &extra_borders
, NULL
);
2411 f
->shell_position
= xmalloc (sizeof "=x++" + 4 * INT_STRLEN_BOUND (int));
2413 /* Convert our geometry parameters into a geometry string
2415 Note that we do not specify here whether the position
2416 is a user-specified or program-specified one.
2417 We pass that information later, in x_wm_set_size_hints. */
2419 int left
= f
->left_pos
;
2420 bool xneg
= (window_prompting
& XNegative
) != 0;
2421 int top
= f
->top_pos
;
2422 bool yneg
= (window_prompting
& YNegative
) != 0;
2428 if (window_prompting
& USPosition
)
2429 sprintf (f
->shell_position
, "=%dx%d%c%d%c%d",
2430 FRAME_PIXEL_WIDTH (f
) + extra_borders
,
2431 FRAME_PIXEL_HEIGHT (f
) + menubar_size
+ extra_borders
,
2432 (xneg
? '-' : '+'), left
,
2433 (yneg
? '-' : '+'), top
);
2436 sprintf (f
->shell_position
, "=%dx%d",
2437 FRAME_PIXEL_WIDTH (f
) + extra_borders
,
2438 FRAME_PIXEL_HEIGHT (f
) + menubar_size
+ extra_borders
);
2440 /* Setting x and y when the position is not specified in
2441 the geometry string will set program position in the WM hints.
2442 If Emacs had just one program position, we could set it in
2443 fallback resources, but since each make-frame call can specify
2444 different program positions, this is easier. */
2445 XtSetArg (gal
[gac
], XtNx
, left
); gac
++;
2446 XtSetArg (gal
[gac
], XtNy
, top
); gac
++;
2450 XtSetArg (gal
[gac
], XtNgeometry
, f
->shell_position
); gac
++;
2451 XtSetValues (shell_widget
, gal
, gac
);
2454 XtManageChild (pane_widget
);
2455 XtRealizeWidget (shell_widget
);
2457 if (FRAME_X_EMBEDDED_P (f
))
2458 XReparentWindow (FRAME_X_DISPLAY (f
), XtWindow (shell_widget
),
2459 f
->output_data
.x
->parent_desc
, 0, 0);
2461 FRAME_X_WINDOW (f
) = XtWindow (frame_widget
);
2463 validate_x_resource_name ();
2465 class_hints
.res_name
= SSDATA (Vx_resource_name
);
2466 class_hints
.res_class
= SSDATA (Vx_resource_class
);
2467 XSetClassHint (FRAME_X_DISPLAY (f
), XtWindow (shell_widget
), &class_hints
);
2470 FRAME_XIC (f
) = NULL
;
2472 create_frame_xic (f
);
2475 f
->output_data
.x
->wm_hints
.input
= True
;
2476 f
->output_data
.x
->wm_hints
.flags
|= InputHint
;
2477 XSetWMHints (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2478 &f
->output_data
.x
->wm_hints
);
2480 hack_wm_protocols (f
, shell_widget
);
2483 XtAddEventHandler (shell_widget
, 0, True
, _XEditResCheckMessages
, 0);
2486 /* Do a stupid property change to force the server to generate a
2487 PropertyNotify event so that the event_stream server timestamp will
2488 be initialized to something relevant to the time we created the window.
2490 XChangeProperty (XtDisplay (frame_widget
), XtWindow (frame_widget
),
2491 FRAME_DISPLAY_INFO (f
)->Xatom_wm_protocols
,
2492 XA_ATOM
, 32, PropModeAppend
, NULL
, 0);
2494 /* Make all the standard events reach the Emacs frame. */
2495 attributes
.event_mask
= STANDARD_EVENT_SET
;
2500 /* XIM server might require some X events. */
2501 unsigned long fevent
= NoEventMask
;
2502 XGetICValues (FRAME_XIC (f
), XNFilterEvents
, &fevent
, NULL
);
2503 attributes
.event_mask
|= fevent
;
2505 #endif /* HAVE_X_I18N */
2507 attribute_mask
= CWEventMask
;
2508 XChangeWindowAttributes (XtDisplay (shell_widget
), XtWindow (shell_widget
),
2509 attribute_mask
, &attributes
);
2511 XtMapWidget (frame_widget
);
2513 /* x_set_name normally ignores requests to set the name if the
2514 requested name is the same as the current name. This is the one
2515 place where that assumption isn't correct; f->name is set, but
2516 the X server hasn't been told. */
2519 bool explicit = f
->explicit_name
;
2521 f
->explicit_name
= false;
2523 fset_name (f
, Qnil
);
2524 x_set_name (f
, name
, explicit);
2527 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2528 f
->output_data
.x
->current_cursor
2529 = f
->output_data
.x
->text_cursor
);
2533 /* This is a no-op, except under Motif. Make sure main areas are
2534 set to something reasonable, in case we get an error later. */
2535 lw_set_main_areas (pane_widget
, 0, frame_widget
);
2538 #else /* not USE_X_TOOLKIT */
2541 x_window (struct frame
*f
)
2543 if (! xg_create_frame_widgets (f
))
2544 error ("Unable to create window");
2547 FRAME_XIC (f
) = NULL
;
2551 create_frame_xic (f
);
2554 /* XIM server might require some X events. */
2555 unsigned long fevent
= NoEventMask
;
2556 XGetICValues (FRAME_XIC (f
), XNFilterEvents
, &fevent
, NULL
);
2558 if (fevent
!= NoEventMask
)
2560 XSetWindowAttributes attributes
;
2561 XWindowAttributes wattr
;
2562 unsigned long attribute_mask
;
2564 XGetWindowAttributes (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2566 attributes
.event_mask
= wattr
.your_event_mask
| fevent
;
2567 attribute_mask
= CWEventMask
;
2568 XChangeWindowAttributes (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2569 attribute_mask
, &attributes
);
2577 #else /*! USE_GTK */
2578 /* Create and set up the X window for frame F. */
2581 x_window (struct frame
*f
)
2583 XClassHint class_hints
;
2584 XSetWindowAttributes attributes
;
2585 unsigned long attribute_mask
;
2587 attributes
.background_pixel
= FRAME_BACKGROUND_PIXEL (f
);
2588 attributes
.border_pixel
= f
->output_data
.x
->border_pixel
;
2589 attributes
.bit_gravity
= StaticGravity
;
2590 attributes
.backing_store
= NotUseful
;
2591 attributes
.save_under
= True
;
2592 attributes
.event_mask
= STANDARD_EVENT_SET
;
2593 attributes
.colormap
= FRAME_X_COLORMAP (f
);
2594 attribute_mask
= (CWBackPixel
| CWBorderPixel
| CWBitGravity
| CWEventMask
2599 = XCreateWindow (FRAME_X_DISPLAY (f
),
2600 f
->output_data
.x
->parent_desc
,
2603 FRAME_PIXEL_WIDTH (f
), FRAME_PIXEL_HEIGHT (f
),
2605 CopyFromParent
, /* depth */
2606 InputOutput
, /* class */
2608 attribute_mask
, &attributes
);
2613 create_frame_xic (f
);
2616 /* XIM server might require some X events. */
2617 unsigned long fevent
= NoEventMask
;
2618 XGetICValues (FRAME_XIC (f
), XNFilterEvents
, &fevent
, NULL
);
2619 attributes
.event_mask
|= fevent
;
2620 attribute_mask
= CWEventMask
;
2621 XChangeWindowAttributes (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2622 attribute_mask
, &attributes
);
2625 #endif /* HAVE_X_I18N */
2627 validate_x_resource_name ();
2629 class_hints
.res_name
= SSDATA (Vx_resource_name
);
2630 class_hints
.res_class
= SSDATA (Vx_resource_class
);
2631 XSetClassHint (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), &class_hints
);
2633 /* This indicates that we use the "Passive Input" input model.
2634 Unless we do this, we don't get the Focus{In,Out} events that we
2635 need to draw the cursor correctly. Accursed bureaucrats.
2636 XWhipsAndChains (FRAME_X_DISPLAY (f), IronMaiden, &TheRack); */
2638 f
->output_data
.x
->wm_hints
.input
= True
;
2639 f
->output_data
.x
->wm_hints
.flags
|= InputHint
;
2640 XSetWMHints (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2641 &f
->output_data
.x
->wm_hints
);
2642 f
->output_data
.x
->wm_hints
.icon_pixmap
= None
;
2644 /* Request "save yourself" and "delete window" commands from wm. */
2647 protocols
[0] = FRAME_DISPLAY_INFO (f
)->Xatom_wm_delete_window
;
2648 protocols
[1] = FRAME_DISPLAY_INFO (f
)->Xatom_wm_save_yourself
;
2649 XSetWMProtocols (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), protocols
, 2);
2652 /* x_set_name normally ignores requests to set the name if the
2653 requested name is the same as the current name. This is the one
2654 place where that assumption isn't correct; f->name is set, but
2655 the X server hasn't been told. */
2658 bool explicit = f
->explicit_name
;
2660 f
->explicit_name
= false;
2662 fset_name (f
, Qnil
);
2663 x_set_name (f
, name
, explicit);
2666 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2667 f
->output_data
.x
->current_cursor
2668 = f
->output_data
.x
->text_cursor
);
2672 if (FRAME_X_WINDOW (f
) == 0)
2673 error ("Unable to create window");
2676 #endif /* not USE_GTK */
2677 #endif /* not USE_X_TOOLKIT */
2679 /* Verify that the icon position args for this window are valid. */
2682 x_icon_verify (struct frame
*f
, Lisp_Object parms
)
2684 Lisp_Object icon_x
, icon_y
;
2686 /* Set the position of the icon. Note that twm groups all
2687 icons in an icon window. */
2688 icon_x
= x_frame_get_and_record_arg (f
, parms
, Qicon_left
, 0, 0, RES_TYPE_NUMBER
);
2689 icon_y
= x_frame_get_and_record_arg (f
, parms
, Qicon_top
, 0, 0, RES_TYPE_NUMBER
);
2690 if (!EQ (icon_x
, Qunbound
) && !EQ (icon_y
, Qunbound
))
2692 CHECK_NUMBER (icon_x
);
2693 CHECK_NUMBER (icon_y
);
2695 else if (!EQ (icon_x
, Qunbound
) || !EQ (icon_y
, Qunbound
))
2696 error ("Both left and top icon corners of icon must be specified");
2699 /* Handle the icon stuff for this window. Perhaps later we might
2700 want an x_set_icon_position which can be called interactively as
2704 x_icon (struct frame
*f
, Lisp_Object parms
)
2706 /* Set the position of the icon. Note that twm groups all
2707 icons in an icon window. */
2709 = x_frame_get_and_record_arg (f
, parms
, Qicon_left
, 0, 0, RES_TYPE_NUMBER
);
2711 = x_frame_get_and_record_arg (f
, parms
, Qicon_top
, 0, 0, RES_TYPE_NUMBER
);
2712 if (!EQ (icon_x
, Qunbound
) && !EQ (icon_y
, Qunbound
))
2714 CHECK_TYPE_RANGED_INTEGER (int, icon_x
);
2715 CHECK_TYPE_RANGED_INTEGER (int, icon_y
);
2717 else if (!EQ (icon_x
, Qunbound
) || !EQ (icon_y
, Qunbound
))
2718 error ("Both left and top icon corners of icon must be specified");
2722 if (! EQ (icon_x
, Qunbound
))
2723 x_wm_set_icon_position (f
, XINT (icon_x
), XINT (icon_y
));
2725 #if false /* x_get_arg removes the visibility parameter as a side effect,
2726 but x_create_frame still needs it. */
2727 /* Start up iconic or window? */
2728 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
2729 x_wm_set_window_state
2730 (f
, (EQ (x_get_arg (dpyinfo
, parms
, Qvisibility
, 0, 0, RES_TYPE_SYMBOL
),
2736 x_text_icon (f
, SSDATA ((!NILP (f
->icon_name
)
2743 /* Make the GCs needed for this window, setting the
2744 background, border and mouse colors; also create the
2745 mouse cursor and the gray border tile. */
2748 x_make_gc (struct frame
*f
)
2750 XGCValues gc_values
;
2754 /* Create the GCs of this frame.
2755 Note that many default values are used. */
2757 gc_values
.foreground
= FRAME_FOREGROUND_PIXEL (f
);
2758 gc_values
.background
= FRAME_BACKGROUND_PIXEL (f
);
2759 gc_values
.line_width
= 0; /* Means 1 using fast algorithm. */
2760 f
->output_data
.x
->normal_gc
2761 = XCreateGC (FRAME_X_DISPLAY (f
),
2763 GCLineWidth
| GCForeground
| GCBackground
,
2766 /* Reverse video style. */
2767 gc_values
.foreground
= FRAME_BACKGROUND_PIXEL (f
);
2768 gc_values
.background
= FRAME_FOREGROUND_PIXEL (f
);
2769 f
->output_data
.x
->reverse_gc
2770 = XCreateGC (FRAME_X_DISPLAY (f
),
2772 GCForeground
| GCBackground
| GCLineWidth
,
2775 /* Cursor has cursor-color background, background-color foreground. */
2776 gc_values
.foreground
= FRAME_BACKGROUND_PIXEL (f
);
2777 gc_values
.background
= f
->output_data
.x
->cursor_pixel
;
2778 gc_values
.fill_style
= FillOpaqueStippled
;
2779 f
->output_data
.x
->cursor_gc
2780 = XCreateGC (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2781 (GCForeground
| GCBackground
2782 | GCFillStyle
| GCLineWidth
),
2785 /* Create the gray border tile used when the pointer is not in
2786 the frame. Since this depends on the frame's pixel values,
2787 this must be done on a per-frame basis. */
2788 f
->output_data
.x
->border_tile
2789 = (XCreatePixmapFromBitmapData
2790 (FRAME_X_DISPLAY (f
), FRAME_DISPLAY_INFO (f
)->root_window
,
2791 gray_bits
, gray_width
, gray_height
,
2792 FRAME_FOREGROUND_PIXEL (f
),
2793 FRAME_BACKGROUND_PIXEL (f
),
2794 DefaultDepth (FRAME_X_DISPLAY (f
), FRAME_X_SCREEN_NUMBER (f
))));
2800 /* Free what was allocated in x_make_gc. */
2803 x_free_gcs (struct frame
*f
)
2805 Display
*dpy
= FRAME_X_DISPLAY (f
);
2809 if (f
->output_data
.x
->normal_gc
)
2811 XFreeGC (dpy
, f
->output_data
.x
->normal_gc
);
2812 f
->output_data
.x
->normal_gc
= 0;
2815 if (f
->output_data
.x
->reverse_gc
)
2817 XFreeGC (dpy
, f
->output_data
.x
->reverse_gc
);
2818 f
->output_data
.x
->reverse_gc
= 0;
2821 if (f
->output_data
.x
->cursor_gc
)
2823 XFreeGC (dpy
, f
->output_data
.x
->cursor_gc
);
2824 f
->output_data
.x
->cursor_gc
= 0;
2827 if (f
->output_data
.x
->border_tile
)
2829 XFreePixmap (dpy
, f
->output_data
.x
->border_tile
);
2830 f
->output_data
.x
->border_tile
= 0;
2837 /* Handler for signals raised during x_create_frame and
2838 x_create_tip_frame. FRAME is the frame which is partially
2842 unwind_create_frame (Lisp_Object frame
)
2844 struct frame
*f
= XFRAME (frame
);
2846 /* If frame is already dead, nothing to do. This can happen if the
2847 display is disconnected after the frame has become official, but
2848 before x_create_frame removes the unwind protect. */
2849 if (!FRAME_LIVE_P (f
))
2852 /* If frame is ``official'', nothing to do. */
2853 if (NILP (Fmemq (frame
, Vframe_list
)))
2855 #if defined GLYPH_DEBUG && defined ENABLE_CHECKING
2856 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
2859 /* If the frame's image cache refcount is still the same as our
2860 private shadow variable, it means we are unwinding a frame
2861 for which we didn't yet call init_frame_faces, where the
2862 refcount is incremented. Therefore, we increment it here, so
2863 that free_frame_faces, called in x_free_frame_resources
2864 below, will not mistakenly decrement the counter that was not
2865 incremented yet to account for this new frame. */
2866 if (FRAME_IMAGE_CACHE (f
) != NULL
2867 && FRAME_IMAGE_CACHE (f
)->refcount
== image_cache_refcount
)
2868 FRAME_IMAGE_CACHE (f
)->refcount
++;
2870 x_free_frame_resources (f
);
2873 #if defined GLYPH_DEBUG && defined ENABLE_CHECKING
2874 /* Check that reference counts are indeed correct. */
2875 eassert (dpyinfo
->reference_count
== dpyinfo_refcount
);
2876 eassert (dpyinfo
->terminal
->image_cache
->refcount
== image_cache_refcount
);
2885 do_unwind_create_frame (Lisp_Object frame
)
2887 unwind_create_frame (frame
);
2891 x_default_font_parameter (struct frame
*f
, Lisp_Object parms
)
2893 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
2894 Lisp_Object font_param
= x_get_arg (dpyinfo
, parms
, Qfont
, NULL
, NULL
,
2896 Lisp_Object font
= Qnil
;
2897 if (EQ (font_param
, Qunbound
))
2900 if (NILP (font_param
))
2902 /* System font should take precedence over X resources. We suggest this
2903 regardless of font-use-system-font because .emacs may not have been
2905 const char *system_font
= xsettings_get_system_font ();
2907 font
= font_open_by_name (f
, build_unibyte_string (system_font
));
2911 font
= !NILP (font_param
) ? font_param
2912 : x_get_arg (dpyinfo
, parms
, Qfont
, "font", "Font", RES_TYPE_STRING
);
2914 if (! FONTP (font
) && ! STRINGP (font
))
2919 /* This will find the normal Xft font. */
2922 "-adobe-courier-medium-r-*-*-*-120-*-*-*-*-iso8859-1",
2923 "-misc-fixed-medium-r-normal-*-*-140-*-*-c-*-iso8859-1",
2924 "-*-*-medium-r-normal-*-*-140-*-*-c-*-iso8859-1",
2925 /* This was formerly the first thing tried, but it finds
2926 too many fonts and takes too long. */
2927 "-*-*-medium-r-*-*-*-*-*-*-c-*-iso8859-1",
2928 /* If those didn't work, look for something which will
2930 "-*-fixed-*-*-*-*-*-140-*-*-c-*-iso8859-1",
2935 for (i
= 0; names
[i
]; i
++)
2937 font
= font_open_by_name (f
, build_unibyte_string (names
[i
]));
2942 error ("No suitable font was found");
2944 else if (!NILP (font_param
))
2946 /* Remember the explicit font parameter, so we can re-apply it after
2947 we've applied the `default' face settings. */
2948 AUTO_FRAME_ARG (arg
, Qfont_param
, font_param
);
2949 x_set_frame_parameters (f
, arg
);
2952 /* This call will make X resources override any system font setting. */
2953 x_default_parameter (f
, parms
, Qfont
, font
, "font", "Font", RES_TYPE_STRING
);
2957 DEFUN ("x-wm-set-size-hint", Fx_wm_set_size_hint
, Sx_wm_set_size_hint
,
2959 doc
: /* Send the size hints for frame FRAME to the window manager.
2960 If FRAME is omitted or nil, use the selected frame.
2961 Signal error if FRAME is not an X frame. */)
2964 struct frame
*f
= decode_window_system_frame (frame
);
2967 x_wm_set_size_hint (f
, 0, false);
2973 set_machine_and_pid_properties (struct frame
*f
)
2975 /* This will set WM_CLIENT_MACHINE and WM_LOCALE_NAME. */
2976 XSetWMProperties (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
), NULL
, NULL
,
2977 NULL
, 0, NULL
, NULL
, NULL
);
2978 pid_t pid
= getpid ();
2979 if (pid
<= 0xffffffffu
)
2981 unsigned long xpid
= pid
;
2982 XChangeProperty (FRAME_X_DISPLAY (f
),
2983 FRAME_OUTER_WINDOW (f
),
2984 XInternAtom (FRAME_X_DISPLAY (f
),
2987 XA_CARDINAL
, 32, PropModeReplace
,
2988 (unsigned char *) &xpid
, 1);
2992 DEFUN ("x-create-frame", Fx_create_frame
, Sx_create_frame
,
2994 doc
: /* Make a new X window, which is called a "frame" in Emacs terms.
2995 Return an Emacs frame object. PARMS is an alist of frame parameters.
2996 If the parameters specify that the frame should not have a minibuffer,
2997 and do not specify a specific minibuffer window to use, then
2998 `default-minibuffer-frame' must be a frame whose minibuffer can be
2999 shared by the new frame.
3001 This function is an internal primitive--use `make-frame' instead. */)
3005 Lisp_Object frame
, tem
;
3007 bool minibuffer_only
= false;
3008 long window_prompting
= 0;
3009 ptrdiff_t count
= SPECPDL_INDEX ();
3010 Lisp_Object display
;
3011 struct x_display_info
*dpyinfo
= NULL
;
3014 int x_width
= 0, x_height
= 0;
3016 parms
= Fcopy_alist (parms
);
3018 /* Use this general default value to start with
3019 until we know if this frame has a specified name. */
3020 Vx_resource_name
= Vinvocation_name
;
3022 display
= x_get_arg (dpyinfo
, parms
, Qterminal
, 0, 0, RES_TYPE_NUMBER
);
3023 if (EQ (display
, Qunbound
))
3024 display
= x_get_arg (dpyinfo
, parms
, Qdisplay
, 0, 0, RES_TYPE_STRING
);
3025 if (EQ (display
, Qunbound
))
3027 dpyinfo
= check_x_display_info (display
);
3028 kb
= dpyinfo
->terminal
->kboard
;
3030 if (!dpyinfo
->terminal
->name
)
3031 error ("Terminal is not live, can't create new frames on it");
3033 name
= x_get_arg (dpyinfo
, parms
, Qname
, "name", "Name", RES_TYPE_STRING
);
3035 && ! EQ (name
, Qunbound
)
3037 error ("Invalid frame name--not a string or nil");
3040 Vx_resource_name
= name
;
3042 /* See if parent window is specified. */
3043 parent
= x_get_arg (dpyinfo
, parms
, Qparent_id
, NULL
, NULL
, RES_TYPE_NUMBER
);
3044 if (EQ (parent
, Qunbound
))
3046 if (! NILP (parent
))
3047 CHECK_NUMBER (parent
);
3050 tem
= x_get_arg (dpyinfo
, parms
, Qminibuffer
, "minibuffer", "Minibuffer",
3052 if (EQ (tem
, Qnone
) || NILP (tem
))
3053 f
= make_frame_without_minibuffer (Qnil
, kb
, display
);
3054 else if (EQ (tem
, Qonly
))
3056 f
= make_minibuffer_frame ();
3057 minibuffer_only
= true;
3059 else if (WINDOWP (tem
))
3060 f
= make_frame_without_minibuffer (tem
, kb
, display
);
3062 f
= make_frame (true);
3064 XSETFRAME (frame
, f
);
3066 f
->terminal
= dpyinfo
->terminal
;
3068 f
->output_method
= output_x_window
;
3069 f
->output_data
.x
= xzalloc (sizeof *f
->output_data
.x
);
3070 f
->output_data
.x
->icon_bitmap
= -1;
3071 FRAME_FONTSET (f
) = -1;
3072 f
->output_data
.x
->scroll_bar_foreground_pixel
= -1;
3073 f
->output_data
.x
->scroll_bar_background_pixel
= -1;
3074 #if defined (USE_LUCID) && defined (USE_TOOLKIT_SCROLL_BARS)
3075 f
->output_data
.x
->scroll_bar_top_shadow_pixel
= -1;
3076 f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
= -1;
3077 #endif /* USE_LUCID && USE_TOOLKIT_SCROLL_BARS */
3078 f
->output_data
.x
->white_relief
.pixel
= -1;
3079 f
->output_data
.x
->black_relief
.pixel
= -1;
3082 x_get_arg (dpyinfo
, parms
, Qicon_name
, "iconName", "Title",
3084 if (! STRINGP (f
->icon_name
))
3085 fset_icon_name (f
, Qnil
);
3087 FRAME_DISPLAY_INFO (f
) = dpyinfo
;
3089 /* With FRAME_DISPLAY_INFO set up, this unwind-protect is safe. */
3090 record_unwind_protect (do_unwind_create_frame
, frame
);
3092 /* These colors will be set anyway later, but it's important
3093 to get the color reference counts right, so initialize them! */
3097 /* Function x_decode_color can signal an error. Make
3098 sure to initialize color slots so that we won't try
3099 to free colors we haven't allocated. */
3100 FRAME_FOREGROUND_PIXEL (f
) = -1;
3101 FRAME_BACKGROUND_PIXEL (f
) = -1;
3102 f
->output_data
.x
->cursor_pixel
= -1;
3103 f
->output_data
.x
->cursor_foreground_pixel
= -1;
3104 f
->output_data
.x
->border_pixel
= -1;
3105 f
->output_data
.x
->mouse_pixel
= -1;
3107 black
= build_string ("black");
3108 FRAME_FOREGROUND_PIXEL (f
)
3109 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
3110 FRAME_BACKGROUND_PIXEL (f
)
3111 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
3112 f
->output_data
.x
->cursor_pixel
3113 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
3114 f
->output_data
.x
->cursor_foreground_pixel
3115 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
3116 f
->output_data
.x
->border_pixel
3117 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
3118 f
->output_data
.x
->mouse_pixel
3119 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
3122 /* Specify the parent under which to make this X window. */
3125 f
->output_data
.x
->parent_desc
= (Window
) XFASTINT (parent
);
3126 f
->output_data
.x
->explicit_parent
= true;
3130 f
->output_data
.x
->parent_desc
= FRAME_DISPLAY_INFO (f
)->root_window
;
3131 f
->output_data
.x
->explicit_parent
= false;
3134 /* Set the name; the functions to which we pass f expect the name to
3136 if (EQ (name
, Qunbound
) || NILP (name
))
3138 fset_name (f
, build_string (dpyinfo
->x_id_name
));
3139 f
->explicit_name
= false;
3143 fset_name (f
, name
);
3144 f
->explicit_name
= true;
3145 /* Use the frame's title when getting resources for this frame. */
3146 specbind (Qx_resource_name
, name
);
3150 register_font_driver (&ftcrfont_driver
, f
);
3152 #ifdef HAVE_FREETYPE
3154 register_font_driver (&xftfont_driver
, f
);
3155 #else /* not HAVE_XFT */
3156 register_font_driver (&ftxfont_driver
, f
);
3157 #endif /* not HAVE_XFT */
3158 #endif /* HAVE_FREETYPE */
3159 register_font_driver (&xfont_driver
, f
);
3160 #endif /* not USE_CAIRO */
3162 image_cache_refcount
=
3163 FRAME_IMAGE_CACHE (f
) ? FRAME_IMAGE_CACHE (f
)->refcount
: 0;
3165 dpyinfo_refcount
= dpyinfo
->reference_count
;
3166 #endif /* GLYPH_DEBUG */
3168 x_default_parameter (f
, parms
, Qfont_backend
, Qnil
,
3169 "fontBackend", "FontBackend", RES_TYPE_STRING
);
3171 /* Extract the window parameters from the supplied values
3172 that are needed to determine window geometry. */
3173 x_default_font_parameter (f
, parms
);
3174 if (!FRAME_FONT (f
))
3176 delete_frame (frame
, Qnoelisp
);
3177 error ("Invalid frame font");
3180 /* Frame contents get displaced if an embedded X window has a border. */
3181 if (! FRAME_X_EMBEDDED_P (f
))
3182 x_default_parameter (f
, parms
, Qborder_width
, make_number (0),
3183 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
3185 /* This defaults to 1 in order to match xterm. We recognize either
3186 internalBorderWidth or internalBorder (which is what xterm calls
3188 if (NILP (Fassq (Qinternal_border_width
, parms
)))
3192 value
= x_get_arg (dpyinfo
, parms
, Qinternal_border_width
,
3193 "internalBorder", "internalBorder", RES_TYPE_NUMBER
);
3194 if (! EQ (value
, Qunbound
))
3195 parms
= Fcons (Fcons (Qinternal_border_width
, value
),
3198 x_default_parameter (f
, parms
, Qinternal_border_width
,
3199 #ifdef USE_GTK /* We used to impose 0 in xg_create_frame_widgets. */
3204 "internalBorderWidth", "internalBorderWidth",
3206 x_default_parameter (f
, parms
, Qright_divider_width
, make_number (0),
3207 NULL
, NULL
, RES_TYPE_NUMBER
);
3208 x_default_parameter (f
, parms
, Qbottom_divider_width
, make_number (0),
3209 NULL
, NULL
, RES_TYPE_NUMBER
);
3210 x_default_parameter (f
, parms
, Qvertical_scroll_bars
,
3211 #if defined (USE_GTK) && defined (USE_TOOLKIT_SCROLL_BARS)
3216 "verticalScrollBars", "ScrollBars",
3218 x_default_parameter (f
, parms
, Qhorizontal_scroll_bars
, Qnil
,
3219 "horizontalScrollBars", "ScrollBars",
3221 /* Also do the stuff which must be set before the window exists. */
3222 x_default_parameter (f
, parms
, Qforeground_color
, build_string ("black"),
3223 "foreground", "Foreground", RES_TYPE_STRING
);
3224 x_default_parameter (f
, parms
, Qbackground_color
, build_string ("white"),
3225 "background", "Background", RES_TYPE_STRING
);
3226 x_default_parameter (f
, parms
, Qmouse_color
, build_string ("black"),
3227 "pointerColor", "Foreground", RES_TYPE_STRING
);
3228 x_default_parameter (f
, parms
, Qborder_color
, build_string ("black"),
3229 "borderColor", "BorderColor", RES_TYPE_STRING
);
3230 x_default_parameter (f
, parms
, Qscreen_gamma
, Qnil
,
3231 "screenGamma", "ScreenGamma", RES_TYPE_FLOAT
);
3232 x_default_parameter (f
, parms
, Qline_spacing
, Qnil
,
3233 "lineSpacing", "LineSpacing", RES_TYPE_NUMBER
);
3234 x_default_parameter (f
, parms
, Qleft_fringe
, Qnil
,
3235 "leftFringe", "LeftFringe", RES_TYPE_NUMBER
);
3236 x_default_parameter (f
, parms
, Qright_fringe
, Qnil
,
3237 "rightFringe", "RightFringe", RES_TYPE_NUMBER
);
3239 x_default_scroll_bar_color_parameter (f
, parms
, Qscroll_bar_foreground
,
3240 "scrollBarForeground",
3241 "ScrollBarForeground", true);
3242 x_default_scroll_bar_color_parameter (f
, parms
, Qscroll_bar_background
,
3243 "scrollBarBackground",
3244 "ScrollBarBackground", false);
3246 /* Init faces before x_default_parameter is called for the
3247 scroll-bar-width parameter because otherwise we end up in
3248 init_iterator with a null face cache, which should not happen. */
3249 init_frame_faces (f
);
3251 /* The following call of change_frame_size is needed since otherwise
3252 x_set_tool_bar_lines will already work with the character sizes
3253 installed by init_frame_faces while the frame's pixel size is
3254 still calculated from a character size of 1 and we subsequently
3255 hit the (height >= 0) assertion in window_box_height.
3257 The non-pixelwise code apparently worked around this because it
3258 had one frame line vs one toolbar line which left us with a zero
3259 root window height which was obviously wrong as well ... */
3260 adjust_frame_size (f
, FRAME_COLS (f
) * FRAME_COLUMN_WIDTH (f
),
3261 FRAME_LINES (f
) * FRAME_LINE_HEIGHT (f
), 5, true,
3264 /* Set the menu-bar-lines and tool-bar-lines parameters. We don't
3265 look up the X resources controlling the menu-bar and tool-bar
3266 here; they are processed specially at startup, and reflected in
3267 the values of the mode variables. */
3269 x_default_parameter (f
, parms
, Qmenu_bar_lines
,
3270 NILP (Vmenu_bar_mode
)
3271 ? make_number (0) : make_number (1),
3272 NULL
, NULL
, RES_TYPE_NUMBER
);
3273 x_default_parameter (f
, parms
, Qtool_bar_lines
,
3274 NILP (Vtool_bar_mode
)
3275 ? make_number (0) : make_number (1),
3276 NULL
, NULL
, RES_TYPE_NUMBER
);
3278 x_default_parameter (f
, parms
, Qbuffer_predicate
, Qnil
,
3279 "bufferPredicate", "BufferPredicate",
3281 x_default_parameter (f
, parms
, Qtitle
, Qnil
,
3282 "title", "Title", RES_TYPE_STRING
);
3283 x_default_parameter (f
, parms
, Qwait_for_wm
, Qt
,
3284 "waitForWM", "WaitForWM", RES_TYPE_BOOLEAN
);
3285 x_default_parameter (f
, parms
, Qtool_bar_position
,
3286 FRAME_TOOL_BAR_POSITION (f
), 0, 0, RES_TYPE_SYMBOL
);
3288 /* Compute the size of the X window. */
3289 window_prompting
= x_figure_window_size (f
, parms
, true, &x_width
, &x_height
);
3291 tem
= x_get_arg (dpyinfo
, parms
, Qunsplittable
, 0, 0, RES_TYPE_BOOLEAN
);
3292 f
->no_split
= minibuffer_only
|| EQ (tem
, Qt
);
3294 x_icon_verify (f
, parms
);
3296 /* Create the X widget or window. */
3297 #ifdef USE_X_TOOLKIT
3298 x_window (f
, window_prompting
);
3306 /* Now consider the frame official. */
3307 f
->terminal
->reference_count
++;
3308 FRAME_DISPLAY_INFO (f
)->reference_count
++;
3309 Vframe_list
= Fcons (frame
, Vframe_list
);
3311 /* We need to do this after creating the X window, so that the
3312 icon-creation functions can say whose icon they're describing. */
3313 x_default_parameter (f
, parms
, Qicon_type
, Qt
,
3314 "bitmapIcon", "BitmapIcon", RES_TYPE_BOOLEAN
);
3316 x_default_parameter (f
, parms
, Qauto_raise
, Qnil
,
3317 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
3318 x_default_parameter (f
, parms
, Qauto_lower
, Qnil
,
3319 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
3320 x_default_parameter (f
, parms
, Qcursor_type
, Qbox
,
3321 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
3322 x_default_parameter (f
, parms
, Qscroll_bar_width
, Qnil
,
3323 "scrollBarWidth", "ScrollBarWidth",
3325 x_default_parameter (f
, parms
, Qscroll_bar_height
, Qnil
,
3326 "scrollBarHeight", "ScrollBarHeight",
3328 x_default_parameter (f
, parms
, Qalpha
, Qnil
,
3329 "alpha", "Alpha", RES_TYPE_NUMBER
);
3331 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
3332 /* Create the menu bar. */
3333 if (!minibuffer_only
&& FRAME_EXTERNAL_MENU_BAR (f
))
3335 /* If this signals an error, we haven't set size hints for the
3336 frame and we didn't make it visible. */
3337 initialize_frame_menubar (f
);
3340 /* This is a no-op, except under Motif where it arranges the
3341 main window for the widgets on it. */
3342 lw_set_main_areas (f
->output_data
.x
->column_widget
,
3343 f
->output_data
.x
->menubar_widget
,
3344 f
->output_data
.x
->edit_widget
);
3345 #endif /* not USE_GTK */
3347 #endif /* USE_X_TOOLKIT || USE_GTK */
3349 /* Consider frame official, now. */
3350 f
->can_x_set_window_size
= true;
3353 SET_FRAME_WIDTH (f
, x_width
);
3355 SET_FRAME_HEIGHT (f
, x_height
);
3357 /* Tell the server what size and position, etc, we want, and how
3358 badly we want them. This should be done after we have the menu
3359 bar so that its size can be taken into account. */
3361 x_wm_set_size_hint (f
, window_prompting
, false);
3364 adjust_frame_size (f
, FRAME_TEXT_WIDTH (f
), FRAME_TEXT_HEIGHT (f
),
3365 0, true, Qx_create_frame_2
);
3367 /* Process fullscreen parameter here in the hope that normalizing a
3368 fullheight/fullwidth frame will produce the size set by the last
3369 adjust_frame_size call. */
3370 x_default_parameter (f
, parms
, Qfullscreen
, Qnil
,
3371 "fullscreen", "Fullscreen", RES_TYPE_SYMBOL
);
3373 /* Make the window appear on the frame and enable display, unless
3374 the caller says not to. However, with explicit parent, Emacs
3375 cannot control visibility, so don't try. */
3376 if (! f
->output_data
.x
->explicit_parent
)
3378 Lisp_Object visibility
;
3380 visibility
= x_get_arg (dpyinfo
, parms
, Qvisibility
, 0, 0,
3382 if (EQ (visibility
, Qunbound
))
3385 if (EQ (visibility
, Qicon
))
3386 x_iconify_frame (f
);
3387 else if (! NILP (visibility
))
3388 x_make_frame_visible (f
);
3391 /* Must have been Qnil. */
3397 /* Set machine name and pid for the purpose of window managers. */
3398 set_machine_and_pid_properties (f
);
3400 /* Set the WM leader property. GTK does this itself, so this is not
3401 needed when using GTK. */
3402 if (dpyinfo
->client_leader_window
!= 0)
3404 XChangeProperty (FRAME_X_DISPLAY (f
),
3405 FRAME_OUTER_WINDOW (f
),
3406 dpyinfo
->Xatom_wm_client_leader
,
3407 XA_WINDOW
, 32, PropModeReplace
,
3408 (unsigned char *) &dpyinfo
->client_leader_window
, 1);
3413 /* Initialize `default-minibuffer-frame' in case this is the first
3414 frame on this terminal. */
3415 if (FRAME_HAS_MINIBUF_P (f
)
3416 && (!FRAMEP (KVAR (kb
, Vdefault_minibuffer_frame
))
3417 || !FRAME_LIVE_P (XFRAME (KVAR (kb
, Vdefault_minibuffer_frame
)))))
3418 kset_default_minibuffer_frame (kb
, frame
);
3420 /* All remaining specified parameters, which have not been "used"
3421 by x_get_arg and friends, now go in the misc. alist of the frame. */
3422 for (tem
= parms
; CONSP (tem
); tem
= XCDR (tem
))
3423 if (CONSP (XCAR (tem
)) && !NILP (XCAR (XCAR (tem
))))
3424 fset_param_alist (f
, Fcons (XCAR (tem
), f
->param_alist
));
3426 /* Make sure windows on this frame appear in calls to next-window
3427 and similar functions. */
3428 Vwindow_list
= Qnil
;
3430 return unbind_to (count
, frame
);
3434 /* FRAME is used only to get a handle on the X display. We don't pass the
3435 display info directly because we're called from frame.c, which doesn't
3436 know about that structure. */
3439 x_get_focus_frame (struct frame
*frame
)
3441 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (frame
);
3443 if (! dpyinfo
->x_focus_frame
)
3446 XSETFRAME (xfocus
, dpyinfo
->x_focus_frame
);
3451 /* In certain situations, when the window manager follows a
3452 click-to-focus policy, there seems to be no way around calling
3453 XSetInputFocus to give another frame the input focus .
3455 In an ideal world, XSetInputFocus should generally be avoided so
3456 that applications don't interfere with the window manager's focus
3457 policy. But I think it's okay to use when it's clearly done
3458 following a user-command. */
3461 x_focus_frame (struct frame
*f
)
3463 Display
*dpy
= FRAME_X_DISPLAY (f
);
3466 x_catch_errors (dpy
);
3468 if (FRAME_X_EMBEDDED_P (f
))
3470 /* For Xembedded frames, normally the embedder forwards key
3471 events. See XEmbed Protocol Specification at
3472 http://freedesktop.org/wiki/Specifications/xembed-spec */
3473 xembed_request_focus (f
);
3477 XSetInputFocus (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3478 RevertToParent
, CurrentTime
);
3479 x_ewmh_activate_frame (f
);
3482 x_uncatch_errors ();
3487 DEFUN ("xw-color-defined-p", Fxw_color_defined_p
, Sxw_color_defined_p
, 1, 2, 0,
3488 doc
: /* Internal function called by `color-defined-p', which see.
3489 (Note that the Nextstep version of this function ignores FRAME.) */)
3490 (Lisp_Object color
, Lisp_Object frame
)
3493 struct frame
*f
= decode_window_system_frame (frame
);
3495 CHECK_STRING (color
);
3497 if (x_defined_color (f
, SSDATA (color
), &foo
, false))
3503 DEFUN ("xw-color-values", Fxw_color_values
, Sxw_color_values
, 1, 2, 0,
3504 doc
: /* Internal function called by `color-values', which see. */)
3505 (Lisp_Object color
, Lisp_Object frame
)
3508 struct frame
*f
= decode_window_system_frame (frame
);
3510 CHECK_STRING (color
);
3512 if (x_defined_color (f
, SSDATA (color
), &foo
, false))
3513 return list3i (foo
.red
, foo
.green
, foo
.blue
);
3518 DEFUN ("xw-display-color-p", Fxw_display_color_p
, Sxw_display_color_p
, 0, 1, 0,
3519 doc
: /* Internal function called by `display-color-p', which see. */)
3520 (Lisp_Object terminal
)
3522 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3524 if (dpyinfo
->n_planes
<= 2)
3527 switch (dpyinfo
->visual
->class)
3540 DEFUN ("x-display-grayscale-p", Fx_display_grayscale_p
, Sx_display_grayscale_p
,
3542 doc
: /* Return t if the X display supports shades of gray.
3543 Note that color displays do support shades of gray.
3544 The optional argument TERMINAL specifies which display to ask about.
3545 TERMINAL should be a terminal object, a frame or a display name (a string).
3546 If omitted or nil, that stands for the selected frame's display. */)
3547 (Lisp_Object terminal
)
3549 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3551 if (dpyinfo
->n_planes
<= 1)
3554 switch (dpyinfo
->visual
->class)
3569 DEFUN ("x-display-pixel-width", Fx_display_pixel_width
, Sx_display_pixel_width
,
3571 doc
: /* Return the width in pixels of the X display TERMINAL.
3572 The optional argument TERMINAL specifies which display to ask about.
3573 TERMINAL should be a terminal object, a frame or a display name (a string).
3574 If omitted or nil, that stands for the selected frame's display.
3576 On \"multi-monitor\" setups this refers to the pixel width for all
3577 physical monitors associated with TERMINAL. To get information for
3578 each physical monitor, use `display-monitor-attributes-list'. */)
3579 (Lisp_Object terminal
)
3581 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3583 return make_number (x_display_pixel_width (dpyinfo
));
3586 DEFUN ("x-display-pixel-height", Fx_display_pixel_height
,
3587 Sx_display_pixel_height
, 0, 1, 0,
3588 doc
: /* Return the height in pixels of the X display TERMINAL.
3589 The optional argument TERMINAL specifies which display to ask about.
3590 TERMINAL should be a terminal object, a frame or a display name (a string).
3591 If omitted or nil, that stands for the selected frame's display.
3593 On \"multi-monitor\" setups this refers to the pixel height for all
3594 physical monitors associated with TERMINAL. To get information for
3595 each physical monitor, use `display-monitor-attributes-list'. */)
3596 (Lisp_Object terminal
)
3598 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3600 return make_number (x_display_pixel_height (dpyinfo
));
3603 DEFUN ("x-display-planes", Fx_display_planes
, Sx_display_planes
,
3605 doc
: /* Return the number of bitplanes of the X display TERMINAL.
3606 The optional argument TERMINAL specifies which display to ask about.
3607 TERMINAL should be a terminal object, a frame or a display name (a string).
3608 If omitted or nil, that stands for the selected frame's display. */)
3609 (Lisp_Object terminal
)
3611 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3613 return make_number (dpyinfo
->n_planes
);
3616 DEFUN ("x-display-color-cells", Fx_display_color_cells
, Sx_display_color_cells
,
3618 doc
: /* Return the number of color cells of the X display TERMINAL.
3619 The optional argument TERMINAL specifies which display to ask about.
3620 TERMINAL should be a terminal object, a frame or a display name (a string).
3621 If omitted or nil, that stands for the selected frame's display. */)
3622 (Lisp_Object terminal
)
3624 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3626 int nr_planes
= DisplayPlanes (dpyinfo
->display
,
3627 XScreenNumberOfScreen (dpyinfo
->screen
));
3629 /* Truncate nr_planes to 24 to avoid integer overflow.
3630 Some displays says 32, but only 24 bits are actually significant.
3631 There are only very few and rare video cards that have more than
3632 24 significant bits. Also 24 bits is more than 16 million colors,
3633 it "should be enough for everyone". */
3634 if (nr_planes
> 24) nr_planes
= 24;
3636 return make_number (1 << nr_planes
);
3639 DEFUN ("x-server-max-request-size", Fx_server_max_request_size
,
3640 Sx_server_max_request_size
,
3642 doc
: /* Return the maximum request size of the X server of display TERMINAL.
3643 The optional argument TERMINAL specifies which display to ask about.
3644 TERMINAL should be a terminal object, a frame or a display name (a string).
3645 If omitted or nil, that stands for the selected frame's display. */)
3646 (Lisp_Object terminal
)
3648 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3650 return make_number (MAXREQUEST (dpyinfo
->display
));
3653 DEFUN ("x-server-vendor", Fx_server_vendor
, Sx_server_vendor
, 0, 1, 0,
3654 doc
: /* Return the "vendor ID" string of the GUI software on TERMINAL.
3656 (Labeling every distributor as a "vendor" embodies the false assumption
3657 that operating systems cannot be developed and distributed noncommercially.)
3658 The optional argument TERMINAL specifies which display to ask about.
3660 For GNU and Unix systems, this queries the X server software; for
3661 MS-Windows, this queries the OS.
3663 TERMINAL should be a terminal object, a frame or a display name (a string).
3664 If omitted or nil, that stands for the selected frame's display. */)
3665 (Lisp_Object terminal
)
3667 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3668 const char *vendor
= ServerVendor (dpyinfo
->display
);
3670 if (! vendor
) vendor
= "";
3671 return build_string (vendor
);
3674 DEFUN ("x-server-version", Fx_server_version
, Sx_server_version
, 0, 1, 0,
3675 doc
: /* Return the version numbers of the GUI software on TERMINAL.
3676 The value is a list of three integers specifying the version of the GUI
3679 For GNU and Unix system, the first 2 numbers are the version of the X
3680 Protocol used on TERMINAL and the 3rd number is the distributor-specific
3681 release number. For MS-Windows, the 3 numbers report the version and
3682 the build number of the OS.
3684 See also the function `x-server-vendor'.
3686 The optional argument TERMINAL specifies which display to ask about.
3687 TERMINAL should be a terminal object, a frame or a display name (a string).
3688 If omitted or nil, that stands for the selected frame's display. */)
3689 (Lisp_Object terminal
)
3691 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3692 Display
*dpy
= dpyinfo
->display
;
3694 return list3i (ProtocolVersion (dpy
), ProtocolRevision (dpy
),
3695 VendorRelease (dpy
));
3698 DEFUN ("x-display-screens", Fx_display_screens
, Sx_display_screens
, 0, 1, 0,
3699 doc
: /* Return the number of screens on the X server of display TERMINAL.
3700 The optional argument TERMINAL specifies which display to ask about.
3701 TERMINAL should be a terminal object, a frame or a display name (a string).
3702 If omitted or nil, that stands for the selected frame's display. */)
3703 (Lisp_Object terminal
)
3705 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3707 return make_number (ScreenCount (dpyinfo
->display
));
3710 DEFUN ("x-display-mm-height", Fx_display_mm_height
, Sx_display_mm_height
, 0, 1, 0,
3711 doc
: /* Return the height in millimeters of the X display TERMINAL.
3712 The optional argument TERMINAL specifies which display to ask about.
3713 TERMINAL should be a terminal object, a frame or a display name (a string).
3714 If omitted or nil, that stands for the selected frame's display.
3716 On \"multi-monitor\" setups this refers to the height in millimeters for
3717 all physical monitors associated with TERMINAL. To get information
3718 for each physical monitor, use `display-monitor-attributes-list'. */)
3719 (Lisp_Object terminal
)
3721 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3723 return make_number (HeightMMOfScreen (dpyinfo
->screen
));
3726 DEFUN ("x-display-mm-width", Fx_display_mm_width
, Sx_display_mm_width
, 0, 1, 0,
3727 doc
: /* Return the width in millimeters of the X display TERMINAL.
3728 The optional argument TERMINAL specifies which display to ask about.
3729 TERMINAL should be a terminal object, a frame or a display name (a string).
3730 If omitted or nil, that stands for the selected frame's display.
3732 On \"multi-monitor\" setups this refers to the width in millimeters for
3733 all physical monitors associated with TERMINAL. To get information
3734 for each physical monitor, use `display-monitor-attributes-list'. */)
3735 (Lisp_Object terminal
)
3737 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3739 return make_number (WidthMMOfScreen (dpyinfo
->screen
));
3742 DEFUN ("x-display-backing-store", Fx_display_backing_store
,
3743 Sx_display_backing_store
, 0, 1, 0,
3744 doc
: /* Return an indication of whether X display TERMINAL does backing store.
3745 The value may be `always', `when-mapped', or `not-useful'.
3746 The optional argument TERMINAL specifies which display to ask about.
3747 TERMINAL should be a terminal object, a frame or a display name (a string).
3748 If omitted or nil, that stands for the selected frame's display. */)
3749 (Lisp_Object terminal
)
3751 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3754 switch (DoesBackingStore (dpyinfo
->screen
))
3757 result
= intern ("always");
3761 result
= intern ("when-mapped");
3765 result
= intern ("not-useful");
3769 error ("Strange value for BackingStore parameter of screen");
3775 DEFUN ("x-display-visual-class", Fx_display_visual_class
,
3776 Sx_display_visual_class
, 0, 1, 0,
3777 doc
: /* Return the visual class of the X display TERMINAL.
3778 The value is one of the symbols `static-gray', `gray-scale',
3779 `static-color', `pseudo-color', `true-color', or `direct-color'.
3781 The optional argument TERMINAL specifies which display to ask about.
3782 TERMINAL should a terminal object, a frame or a display name (a string).
3783 If omitted or nil, that stands for the selected frame's display. */)
3784 (Lisp_Object terminal
)
3786 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3789 switch (dpyinfo
->visual
->class)
3792 result
= intern ("static-gray");
3795 result
= intern ("gray-scale");
3798 result
= intern ("static-color");
3801 result
= intern ("pseudo-color");
3804 result
= intern ("true-color");
3807 result
= intern ("direct-color");
3810 error ("Display has an unknown visual class");
3816 DEFUN ("x-display-save-under", Fx_display_save_under
,
3817 Sx_display_save_under
, 0, 1, 0,
3818 doc
: /* Return t if the X display TERMINAL supports the save-under feature.
3819 The optional argument TERMINAL specifies which display to ask about.
3820 TERMINAL should be a terminal object, a frame or a display name (a string).
3821 If omitted or nil, that stands for the selected frame's display. */)
3822 (Lisp_Object terminal
)
3824 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3826 if (DoesSaveUnders (dpyinfo
->screen
) == True
)
3832 /* Store the geometry of the workarea on display DPYINFO into *RECT.
3833 Return false if and only if the workarea information cannot be
3834 obtained via the _NET_WORKAREA root window property. */
3836 #if ! GTK_CHECK_VERSION (3, 4, 0)
3838 x_get_net_workarea (struct x_display_info
*dpyinfo
, XRectangle
*rect
)
3840 Display
*dpy
= dpyinfo
->display
;
3841 long offset
, max_len
;
3842 Atom target_type
, actual_type
;
3843 unsigned long actual_size
, bytes_remaining
;
3844 int rc
, actual_format
;
3845 unsigned char *tmp_data
= NULL
;
3846 bool result
= false;
3848 x_catch_errors (dpy
);
3851 target_type
= XA_CARDINAL
;
3852 rc
= XGetWindowProperty (dpy
, dpyinfo
->root_window
,
3853 dpyinfo
->Xatom_net_current_desktop
,
3854 offset
, max_len
, False
, target_type
,
3855 &actual_type
, &actual_format
, &actual_size
,
3856 &bytes_remaining
, &tmp_data
);
3857 if (rc
== Success
&& actual_type
== target_type
&& !x_had_errors_p (dpy
)
3858 && actual_format
== 32 && actual_size
== max_len
)
3860 long current_desktop
= ((long *) tmp_data
)[0];
3865 offset
= 4 * current_desktop
;
3867 rc
= XGetWindowProperty (dpy
, dpyinfo
->root_window
,
3868 dpyinfo
->Xatom_net_workarea
,
3869 offset
, max_len
, False
, target_type
,
3870 &actual_type
, &actual_format
, &actual_size
,
3871 &bytes_remaining
, &tmp_data
);
3872 if (rc
== Success
&& actual_type
== target_type
&& !x_had_errors_p (dpy
)
3873 && actual_format
== 32 && actual_size
== max_len
)
3875 long *values
= (long *) tmp_data
;
3877 rect
->x
= values
[0];
3878 rect
->y
= values
[1];
3879 rect
->width
= values
[2];
3880 rect
->height
= values
[3];
3890 x_uncatch_errors ();
3898 /* Return monitor number where F is "most" or closest to. */
3900 x_get_monitor_for_frame (struct frame
*f
,
3901 struct MonitorInfo
*monitors
,
3905 int area
= 0, dist
= -1;
3906 int best_area
= -1, best_dist
= -1;
3909 if (n_monitors
== 1) return 0;
3910 frect
.x
= f
->left_pos
;
3911 frect
.y
= f
->top_pos
;
3912 frect
.width
= FRAME_PIXEL_WIDTH (f
);
3913 frect
.height
= FRAME_PIXEL_HEIGHT (f
);
3915 for (i
= 0; i
< n_monitors
; ++i
)
3917 struct MonitorInfo
*mi
= &monitors
[i
];
3921 if (mi
->geom
.width
== 0) continue;
3923 if (x_intersect_rectangles (&mi
->geom
, &frect
, &res
))
3925 a
= res
.width
* res
.height
;
3933 if (a
== 0 && area
== 0)
3936 if (frect
.x
+ frect
.width
< mi
->geom
.x
)
3937 dx
= mi
->geom
.x
- frect
.x
+ frect
.width
;
3938 else if (frect
.x
> mi
->geom
.x
+ mi
->geom
.width
)
3939 dx
= frect
.x
- mi
->geom
.x
+ mi
->geom
.width
;
3942 if (frect
.y
+ frect
.height
< mi
->geom
.y
)
3943 dy
= mi
->geom
.y
- frect
.y
+ frect
.height
;
3944 else if (frect
.y
> mi
->geom
.y
+ mi
->geom
.height
)
3945 dy
= frect
.y
- mi
->geom
.y
+ mi
->geom
.height
;
3950 if (dist
== -1 || dist
> d
)
3958 return best_area
!= -1 ? best_area
: (best_dist
!= -1 ? best_dist
: 0);
3962 x_make_monitor_attribute_list (struct MonitorInfo
*monitors
,
3964 int primary_monitor
,
3965 struct x_display_info
*dpyinfo
,
3968 Lisp_Object monitor_frames
= Fmake_vector (make_number (n_monitors
), Qnil
);
3969 Lisp_Object frame
, rest
;
3971 FOR_EACH_FRAME (rest
, frame
)
3973 struct frame
*f
= XFRAME (frame
);
3975 if (FRAME_X_P (f
) && FRAME_DISPLAY_INFO (f
) == dpyinfo
3976 && !EQ (frame
, tip_frame
))
3978 int i
= x_get_monitor_for_frame (f
, monitors
, n_monitors
);
3979 ASET (monitor_frames
, i
, Fcons (frame
, AREF (monitor_frames
, i
)));
3983 return make_monitor_attribute_list (monitors
, n_monitors
, primary_monitor
,
3984 monitor_frames
, source
);
3988 x_get_monitor_attributes_fallback (struct x_display_info
*dpyinfo
)
3990 struct MonitorInfo monitor
;
3991 XRectangle workarea_r
;
3993 /* Fallback: treat (possibly) multiple physical monitors as if they
3994 formed a single monitor as a whole. This should provide a
3995 consistent result at least on single monitor environments. */
3996 monitor
.geom
.x
= monitor
.geom
.y
= 0;
3997 monitor
.geom
.width
= x_display_pixel_width (dpyinfo
);
3998 monitor
.geom
.height
= x_display_pixel_height (dpyinfo
);
3999 monitor
.mm_width
= WidthMMOfScreen (dpyinfo
->screen
);
4000 monitor
.mm_height
= HeightMMOfScreen (dpyinfo
->screen
);
4001 monitor
.name
= xstrdup ("combined screen");
4003 if (x_get_net_workarea (dpyinfo
, &workarea_r
))
4004 monitor
.work
= workarea_r
;
4006 monitor
.work
= monitor
.geom
;
4007 return x_make_monitor_attribute_list (&monitor
, 1, 0, dpyinfo
, "fallback");
4011 #ifdef HAVE_XINERAMA
4013 x_get_monitor_attributes_xinerama (struct x_display_info
*dpyinfo
)
4016 Lisp_Object attributes_list
= Qnil
;
4017 Display
*dpy
= dpyinfo
->display
;
4018 XineramaScreenInfo
*info
= XineramaQueryScreens (dpy
, &n_monitors
);
4019 struct MonitorInfo
*monitors
;
4020 double mm_width_per_pixel
, mm_height_per_pixel
;
4022 if (! info
|| n_monitors
== 0)
4026 return attributes_list
;
4029 mm_width_per_pixel
= ((double) WidthMMOfScreen (dpyinfo
->screen
)
4030 / x_display_pixel_width (dpyinfo
));
4031 mm_height_per_pixel
= ((double) HeightMMOfScreen (dpyinfo
->screen
)
4032 / x_display_pixel_height (dpyinfo
));
4033 monitors
= xzalloc (n_monitors
* sizeof *monitors
);
4034 for (i
= 0; i
< n_monitors
; ++i
)
4036 struct MonitorInfo
*mi
= &monitors
[i
];
4037 XRectangle workarea_r
;
4039 mi
->geom
.x
= info
[i
].x_org
;
4040 mi
->geom
.y
= info
[i
].y_org
;
4041 mi
->geom
.width
= info
[i
].width
;
4042 mi
->geom
.height
= info
[i
].height
;
4043 mi
->mm_width
= mi
->geom
.width
* mm_width_per_pixel
+ 0.5;
4044 mi
->mm_height
= mi
->geom
.height
* mm_height_per_pixel
+ 0.5;
4047 /* Xinerama usually have primary monitor first, just use that. */
4048 if (i
== 0 && x_get_net_workarea (dpyinfo
, &workarea_r
))
4050 mi
->work
= workarea_r
;
4051 if (! x_intersect_rectangles (&mi
->geom
, &mi
->work
, &mi
->work
))
4052 mi
->work
= mi
->geom
;
4055 mi
->work
= mi
->geom
;
4059 attributes_list
= x_make_monitor_attribute_list (monitors
,
4064 free_monitors (monitors
, n_monitors
);
4065 return attributes_list
;
4067 #endif /* HAVE_XINERAMA */
4072 x_get_monitor_attributes_xrandr (struct x_display_info
*dpyinfo
)
4074 Lisp_Object attributes_list
= Qnil
;
4075 XRRScreenResources
*resources
;
4076 Display
*dpy
= dpyinfo
->display
;
4077 int i
, n_monitors
, primary
= -1;
4078 RROutput pxid
= None
;
4079 struct MonitorInfo
*monitors
;
4081 #ifdef HAVE_XRRGETSCREENRESOURCESCURRENT
4082 resources
= XRRGetScreenResourcesCurrent (dpy
, dpyinfo
->root_window
);
4084 resources
= XRRGetScreenResources (dpy
, dpyinfo
->root_window
);
4086 if (! resources
|| resources
->noutput
== 0)
4089 XRRFreeScreenResources (resources
);
4092 n_monitors
= resources
->noutput
;
4093 monitors
= xzalloc (n_monitors
* sizeof *monitors
);
4095 #ifdef HAVE_XRRGETOUTPUTPRIMARY
4096 pxid
= XRRGetOutputPrimary (dpy
, dpyinfo
->root_window
);
4099 for (i
= 0; i
< n_monitors
; ++i
)
4101 XRROutputInfo
*info
= XRRGetOutputInfo (dpy
, resources
,
4102 resources
->outputs
[i
]);
4103 Connection conn
= info
? info
->connection
: RR_Disconnected
;
4104 RRCrtc id
= info
? info
->crtc
: None
;
4106 if (strcmp (info
->name
, "default") == 0)
4108 /* Non XRandr 1.2 driver, does not give useful data. */
4109 XRRFreeOutputInfo (info
);
4110 XRRFreeScreenResources (resources
);
4111 free_monitors (monitors
, n_monitors
);
4115 if (conn
!= RR_Disconnected
&& id
!= None
)
4117 XRRCrtcInfo
*crtc
= XRRGetCrtcInfo (dpy
, resources
, id
);
4118 struct MonitorInfo
*mi
= &monitors
[i
];
4119 XRectangle workarea_r
;
4123 XRRFreeOutputInfo (info
);
4127 mi
->geom
.x
= crtc
->x
;
4128 mi
->geom
.y
= crtc
->y
;
4129 mi
->geom
.width
= crtc
->width
;
4130 mi
->geom
.height
= crtc
->height
;
4131 mi
->mm_width
= info
->mm_width
;
4132 mi
->mm_height
= info
->mm_height
;
4133 mi
->name
= xstrdup (info
->name
);
4135 if (pxid
!= None
&& pxid
== resources
->outputs
[i
])
4137 else if (primary
== -1 && strcmp (info
->name
, "LVDS") == 0)
4140 if (i
== primary
&& x_get_net_workarea (dpyinfo
, &workarea_r
))
4142 mi
->work
= workarea_r
;
4143 if (! x_intersect_rectangles (&mi
->geom
, &mi
->work
, &mi
->work
))
4144 mi
->work
= mi
->geom
;
4147 mi
->work
= mi
->geom
;
4149 XRRFreeCrtcInfo (crtc
);
4151 XRRFreeOutputInfo (info
);
4153 XRRFreeScreenResources (resources
);
4155 attributes_list
= x_make_monitor_attribute_list (monitors
,
4160 free_monitors (monitors
, n_monitors
);
4161 return attributes_list
;
4163 #endif /* HAVE_XRANDR */
4166 x_get_monitor_attributes (struct x_display_info
*dpyinfo
)
4168 Lisp_Object attributes_list
= Qnil
;
4169 Display
*dpy
= dpyinfo
->display
;
4171 (void) dpy
; /* Suppress unused variable warning. */
4174 int xrr_event_base
, xrr_error_base
;
4175 bool xrr_ok
= false;
4176 xrr_ok
= XRRQueryExtension (dpy
, &xrr_event_base
, &xrr_error_base
);
4179 int xrr_major
, xrr_minor
;
4180 XRRQueryVersion (dpy
, &xrr_major
, &xrr_minor
);
4181 xrr_ok
= (xrr_major
== 1 && xrr_minor
>= 2) || xrr_major
> 1;
4185 attributes_list
= x_get_monitor_attributes_xrandr (dpyinfo
);
4186 #endif /* HAVE_XRANDR */
4188 #ifdef HAVE_XINERAMA
4189 if (NILP (attributes_list
))
4191 int xin_event_base
, xin_error_base
;
4192 bool xin_ok
= false;
4193 xin_ok
= XineramaQueryExtension (dpy
, &xin_event_base
, &xin_error_base
);
4194 if (xin_ok
&& XineramaIsActive (dpy
))
4195 attributes_list
= x_get_monitor_attributes_xinerama (dpyinfo
);
4197 #endif /* HAVE_XINERAMA */
4199 if (NILP (attributes_list
))
4200 attributes_list
= x_get_monitor_attributes_fallback (dpyinfo
);
4202 return attributes_list
;
4205 #endif /* !USE_GTK */
4207 DEFUN ("x-display-monitor-attributes-list", Fx_display_monitor_attributes_list
,
4208 Sx_display_monitor_attributes_list
,
4210 doc
: /* Return a list of physical monitor attributes on the X display TERMINAL.
4212 The optional argument TERMINAL specifies which display to ask about.
4213 TERMINAL should be a terminal object, a frame or a display name (a string).
4214 If omitted or nil, that stands for the selected frame's display.
4216 In addition to the standard attribute keys listed in
4217 `display-monitor-attributes-list', the following keys are contained in
4220 source -- String describing the source from which multi-monitor
4221 information is obtained, one of \"Gdk\", \"XRandr\",
4222 \"Xinerama\", or \"fallback\"
4224 Internal use only, use `display-monitor-attributes-list' instead. */)
4225 (Lisp_Object terminal
)
4227 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
4228 Lisp_Object attributes_list
= Qnil
;
4231 double mm_width_per_pixel
, mm_height_per_pixel
;
4234 gint primary_monitor
= 0, n_monitors
, i
;
4235 Lisp_Object monitor_frames
, rest
, frame
;
4236 static const char *source
= "Gdk";
4237 struct MonitorInfo
*monitors
;
4240 mm_width_per_pixel
= ((double) WidthMMOfScreen (dpyinfo
->screen
)
4241 / x_display_pixel_width (dpyinfo
));
4242 mm_height_per_pixel
= ((double) HeightMMOfScreen (dpyinfo
->screen
)
4243 / x_display_pixel_height (dpyinfo
));
4244 gdpy
= gdk_x11_lookup_xdisplay (dpyinfo
->display
);
4245 gscreen
= gdk_display_get_default_screen (gdpy
);
4246 #if GTK_CHECK_VERSION (2, 20, 0)
4247 primary_monitor
= gdk_screen_get_primary_monitor (gscreen
);
4249 n_monitors
= gdk_screen_get_n_monitors (gscreen
);
4250 monitor_frames
= Fmake_vector (make_number (n_monitors
), Qnil
);
4251 monitors
= xzalloc (n_monitors
* sizeof *monitors
);
4253 FOR_EACH_FRAME (rest
, frame
)
4255 struct frame
*f
= XFRAME (frame
);
4257 if (FRAME_X_P (f
) && FRAME_DISPLAY_INFO (f
) == dpyinfo
4258 && !EQ (frame
, tip_frame
))
4260 GdkWindow
*gwin
= gtk_widget_get_window (FRAME_GTK_WIDGET (f
));
4262 i
= gdk_screen_get_monitor_at_window (gscreen
, gwin
);
4263 ASET (monitor_frames
, i
, Fcons (frame
, AREF (monitor_frames
, i
)));
4267 for (i
= 0; i
< n_monitors
; ++i
)
4269 gint width_mm
= -1, height_mm
= -1;
4270 GdkRectangle rec
, work
;
4271 struct MonitorInfo
*mi
= &monitors
[i
];
4273 gdk_screen_get_monitor_geometry (gscreen
, i
, &rec
);
4275 #if GTK_CHECK_VERSION (2, 14, 0)
4276 width_mm
= gdk_screen_get_monitor_width_mm (gscreen
, i
);
4277 height_mm
= gdk_screen_get_monitor_height_mm (gscreen
, i
);
4280 width_mm
= rec
.width
* mm_width_per_pixel
+ 0.5;
4282 height_mm
= rec
.height
* mm_height_per_pixel
+ 0.5;
4284 #if GTK_CHECK_VERSION (3, 4, 0)
4285 gdk_screen_get_monitor_workarea (gscreen
, i
, &work
);
4287 /* Emulate the behavior of GTK+ 3.4. */
4289 XRectangle workarea_r
;
4291 if (i
== primary_monitor
&& x_get_net_workarea (dpyinfo
, &workarea_r
))
4293 work
.x
= workarea_r
.x
;
4294 work
.y
= workarea_r
.y
;
4295 work
.width
= workarea_r
.width
;
4296 work
.height
= workarea_r
.height
;
4297 if (! gdk_rectangle_intersect (&rec
, &work
, &work
))
4308 mi
->geom
.width
= rec
.width
;
4309 mi
->geom
.height
= rec
.height
;
4310 mi
->work
.x
= work
.x
;
4311 mi
->work
.y
= work
.y
;
4312 mi
->work
.width
= work
.width
;
4313 mi
->work
.height
= work
.height
;
4314 mi
->mm_width
= width_mm
;
4315 mi
->mm_height
= height_mm
;
4317 #if GTK_CHECK_VERSION (2, 14, 0)
4318 mi
->name
= gdk_screen_get_monitor_plug_name (gscreen
, i
);
4322 attributes_list
= make_monitor_attribute_list (monitors
,
4328 #else /* not USE_GTK */
4331 attributes_list
= x_get_monitor_attributes (dpyinfo
);
4334 #endif /* not USE_GTK */
4336 return attributes_list
;
4339 /* Return geometric attributes of FRAME. According to the value of
4340 ATTRIBUTES return the outer edges of FRAME (Qouter_edges), the native
4341 edges of FRAME (Qnative_edges), or the inner edges of frame
4342 (Qinner_edges). Any other value means to return the geometry as
4343 returned by Fx_frame_geometry. */
4345 frame_geometry (Lisp_Object frame
, Lisp_Object attribute
)
4347 struct frame
*f
= decode_live_frame (frame
);
4348 /** XWindowAttributes atts; **/
4350 unsigned int ign
, native_width
, native_height
;
4351 int xy_ign
, xptr
, yptr
;
4352 int left_off
, right_off
, top_off
, bottom_off
;
4353 int outer_left
, outer_top
, outer_right
, outer_bottom
;
4354 int native_left
, native_top
, native_right
, native_bottom
;
4355 int inner_left
, inner_top
, inner_right
, inner_bottom
;
4356 int internal_border_width
;
4357 bool menu_bar_external
= false, tool_bar_external
= false;
4358 int menu_bar_height
= 0, menu_bar_width
= 0;
4359 int tool_bar_height
= 0, tool_bar_width
= 0;
4361 if (FRAME_INITIAL_P (f
) || !FRAME_X_P (f
))
4365 XGetGeometry (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
4366 &rootw
, &xy_ign
, &xy_ign
, &native_width
, &native_height
,
4368 /** XGetWindowAttributes (FRAME_X_DISPLAY (f), FRAME_OUTER_WINDOW (f), &atts); **/
4369 x_real_pos_and_offsets (f
, &left_off
, &right_off
, &top_off
, &bottom_off
,
4370 NULL
, NULL
, &xptr
, &yptr
, NULL
);
4373 /** native_width = atts.width; **/
4374 /** native_height = atts.height; **/
4378 outer_right
= outer_left
+ left_off
+ native_width
+ right_off
;
4379 outer_bottom
= outer_top
+ top_off
+ native_height
+ bottom_off
;
4381 native_left
= outer_left
+ left_off
;
4382 native_top
= outer_top
+ top_off
;
4383 native_right
= native_left
+ native_width
;
4384 native_bottom
= native_top
+ native_height
;
4386 internal_border_width
= FRAME_INTERNAL_BORDER_WIDTH (f
);
4387 inner_left
= native_left
+ internal_border_width
;
4388 inner_top
= native_top
+ internal_border_width
;
4389 inner_right
= native_right
- internal_border_width
;
4390 inner_bottom
= native_bottom
- internal_border_width
;
4392 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
4393 menu_bar_external
= true;
4394 menu_bar_height
= FRAME_MENUBAR_HEIGHT (f
);
4395 native_top
+= menu_bar_height
;
4396 inner_top
+= menu_bar_height
;
4398 menu_bar_height
= FRAME_MENU_BAR_HEIGHT (f
);
4399 inner_top
+= menu_bar_height
;
4401 menu_bar_width
= menu_bar_height
? native_width
: 0;
4403 #if defined (USE_GTK)
4404 tool_bar_external
= true;
4405 if (EQ (FRAME_TOOL_BAR_POSITION (f
), Qleft
))
4407 tool_bar_width
= FRAME_TOOLBAR_WIDTH (f
);
4408 native_left
+= tool_bar_width
;
4409 inner_left
+= tool_bar_width
;
4411 = tool_bar_width
? native_height
- menu_bar_height
: 0;
4413 else if (EQ (FRAME_TOOL_BAR_POSITION (f
), Qtop
))
4415 tool_bar_height
= FRAME_TOOLBAR_HEIGHT (f
);
4416 native_top
+= tool_bar_height
;
4417 inner_top
+= tool_bar_height
;
4418 tool_bar_width
= tool_bar_height
? native_width
: 0;
4420 else if (EQ (FRAME_TOOL_BAR_POSITION (f
), Qright
))
4422 tool_bar_width
= FRAME_TOOLBAR_WIDTH (f
);
4423 native_right
-= tool_bar_width
;
4424 inner_right
-= tool_bar_width
;
4426 = tool_bar_width
? native_height
- menu_bar_height
: 0;
4430 tool_bar_height
= FRAME_TOOLBAR_HEIGHT (f
);
4431 native_bottom
-= tool_bar_height
;
4432 inner_bottom
-= tool_bar_height
;
4433 tool_bar_width
= tool_bar_height
? native_width
: 0;
4436 tool_bar_height
= FRAME_TOOL_BAR_HEIGHT (f
);
4437 tool_bar_width
= tool_bar_height
? native_width
: 0;
4438 inner_top
+= tool_bar_height
;
4441 /* Construct list. */
4442 if (EQ (attribute
, Qouter_edges
))
4443 return list4 (make_number (outer_left
), make_number (outer_top
),
4444 make_number (outer_right
), make_number (outer_bottom
));
4445 else if (EQ (attribute
, Qnative_edges
))
4446 return list4 (make_number (native_left
), make_number (native_top
),
4447 make_number (native_right
), make_number (native_bottom
));
4448 else if (EQ (attribute
, Qinner_edges
))
4449 return list4 (make_number (inner_left
), make_number (inner_top
),
4450 make_number (inner_right
), make_number (inner_bottom
));
4453 listn (CONSTYPE_HEAP
, 10,
4454 Fcons (Qouter_position
,
4455 Fcons (make_number (outer_left
),
4456 make_number (outer_top
))),
4458 Fcons (make_number (outer_right
- outer_left
),
4459 make_number (outer_bottom
- outer_top
))),
4461 Fcons (Qexternal_border_size
,
4462 Fcons (make_number (right_off
),
4463 make_number (bottom_off
))),
4465 Fcons (Qtitle_bar_size
,
4466 Fcons (make_number (0),
4467 make_number (top_off
- bottom_off
))),
4468 Fcons (Qmenu_bar_external
, menu_bar_external
? Qt
: Qnil
),
4469 Fcons (Qmenu_bar_size
,
4470 Fcons (make_number (menu_bar_width
),
4471 make_number (menu_bar_height
))),
4472 Fcons (Qtool_bar_external
, tool_bar_external
? Qt
: Qnil
),
4473 Fcons (Qtool_bar_position
, FRAME_TOOL_BAR_POSITION (f
)),
4474 Fcons (Qtool_bar_size
,
4475 Fcons (make_number (tool_bar_width
),
4476 make_number (tool_bar_height
))),
4477 Fcons (Qinternal_border_width
,
4478 make_number (internal_border_width
)));
4481 DEFUN ("x-frame-geometry", Fx_frame_geometry
, Sx_frame_geometry
, 0, 1, 0,
4482 doc
: /* Return geometric attributes of FRAME.
4483 FRAME must be a live frame and defaults to the selected one. The return
4484 value is an association list of the attributes listed below. All height
4485 and width values are in pixels.
4487 `outer-position' is a cons of the outer left and top edges of FRAME
4488 relative to the origin - the position (0, 0) - of FRAME's display.
4490 `outer-size' is a cons of the outer width and height of FRAME. The
4491 outer size includes the title bar and the external borders as well as
4492 any menu and/or tool bar of frame.
4494 `external-border-size' is a cons of the horizontal and vertical width of
4495 FRAME's external borders as supplied by the window manager.
4497 `title-bar-size' is a cons of the width and height of the title bar of
4498 FRAME as supplied by the window manager. If both of them are zero,
4499 FRAME has no title bar. If only the width is zero, Emacs was not
4500 able to retrieve the width information.
4502 `menu-bar-external', if non-nil, means the menu bar is external (never
4503 included in the inner edges of FRAME).
4505 `menu-bar-size' is a cons of the width and height of the menu bar of
4508 `tool-bar-external', if non-nil, means the tool bar is external (never
4509 included in the inner edges of FRAME).
4511 `tool-bar-position' tells on which side the tool bar on FRAME is and can
4512 be one of `left', `top', `right' or `bottom'. If this is nil, FRAME
4515 `tool-bar-size' is a cons of the width and height of the tool bar of
4518 `internal-border-width' is the width of the internal border of
4522 return frame_geometry (frame
, Qnil
);
4525 DEFUN ("x-frame-edges", Fx_frame_edges
, Sx_frame_edges
, 0, 2, 0,
4526 doc
: /* Return edge coordinates of FRAME.
4527 FRAME must be a live frame and defaults to the selected one. The return
4528 value is a list of the form (LEFT, TOP, RIGHT, BOTTOM). All values are
4529 in pixels relative to the origin - the position (0, 0) - of FRAME's
4532 If optional argument TYPE is the symbol `outer-edges', return the outer
4533 edges of FRAME. The outer edges comprise the decorations of the window
4534 manager (like the title bar or external borders) as well as any external
4535 menu or tool bar of FRAME. If optional argument TYPE is the symbol
4536 `native-edges' or nil, return the native edges of FRAME. The native
4537 edges exclude the decorations of the window manager and any external
4538 menu or tool bar of FRAME. If TYPE is the symbol `inner-edges', return
4539 the inner edges of FRAME. These edges exclude title bar, any borders,
4540 menu bar or tool bar of FRAME. */)
4541 (Lisp_Object frame
, Lisp_Object type
)
4543 return frame_geometry (frame
, ((EQ (type
, Qouter_edges
)
4544 || EQ (type
, Qinner_edges
))
4549 DEFUN ("x-mouse-absolute-pixel-position", Fx_mouse_absolute_pixel_position
,
4550 Sx_mouse_absolute_pixel_position
, 0, 0, 0,
4551 doc
: /* Return absolute position of mouse cursor in pixels.
4552 The position is returned as a cons cell (X . Y) of the coordinates of
4553 the mouse cursor position in pixels relative to a position (0, 0) of the
4554 selected frame's display. */)
4557 struct frame
*f
= SELECTED_FRAME ();
4558 Window root
, dummy_window
;
4561 if (FRAME_INITIAL_P (f
) || !FRAME_X_P (f
))
4565 XQueryPointer (FRAME_X_DISPLAY (f
),
4566 DefaultRootWindow (FRAME_X_DISPLAY (f
)),
4567 &root
, &dummy_window
, &x
, &y
, &dummy
, &dummy
,
4568 (unsigned int *) &dummy
);
4571 return Fcons (make_number (x
), make_number (y
));
4574 DEFUN ("x-set-mouse-absolute-pixel-position", Fx_set_mouse_absolute_pixel_position
,
4575 Sx_set_mouse_absolute_pixel_position
, 2, 2, 0,
4576 doc
: /* Move mouse pointer to absolute pixel position (X, Y).
4577 The coordinates X and Y are interpreted in pixels relative to a position
4578 (0, 0) of the selected frame's display. */)
4579 (Lisp_Object x
, Lisp_Object y
)
4581 struct frame
*f
= SELECTED_FRAME ();
4583 if (FRAME_INITIAL_P (f
) || !FRAME_X_P (f
))
4586 CHECK_TYPE_RANGED_INTEGER (int, x
);
4587 CHECK_TYPE_RANGED_INTEGER (int, y
);
4590 XWarpPointer (FRAME_X_DISPLAY (f
), None
, DefaultRootWindow (FRAME_X_DISPLAY (f
)),
4591 0, 0, 0, 0, XINT (x
), XINT (y
));
4597 /************************************************************************
4599 ************************************************************************/
4602 /* Mapping visual names to visuals. */
4604 static struct visual_class
4611 {"StaticGray", StaticGray
},
4612 {"GrayScale", GrayScale
},
4613 {"StaticColor", StaticColor
},
4614 {"PseudoColor", PseudoColor
},
4615 {"TrueColor", TrueColor
},
4616 {"DirectColor", DirectColor
},
4621 #ifndef HAVE_XSCREENNUMBEROFSCREEN
4623 /* Value is the screen number of screen SCR. This is a substitute for
4624 the X function with the same name when that doesn't exist. */
4627 XScreenNumberOfScreen (scr
)
4628 register Screen
*scr
;
4630 Display
*dpy
= scr
->display
;
4633 for (i
= 0; i
< dpy
->nscreens
; ++i
)
4634 if (scr
== dpy
->screens
+ i
)
4640 #endif /* not HAVE_XSCREENNUMBEROFSCREEN */
4643 /* Select the visual that should be used on display DPYINFO. Set
4644 members of DPYINFO appropriately. Called from x_term_init. */
4647 select_visual (struct x_display_info
*dpyinfo
)
4649 Display
*dpy
= dpyinfo
->display
;
4650 Screen
*screen
= dpyinfo
->screen
;
4652 /* See if a visual is specified. */
4653 AUTO_STRING (visualClass
, "visualClass");
4654 AUTO_STRING (VisualClass
, "VisualClass");
4655 Lisp_Object value
= display_x_get_resource (dpyinfo
, visualClass
,
4656 VisualClass
, Qnil
, Qnil
);
4658 if (STRINGP (value
))
4660 /* VALUE should be of the form CLASS-DEPTH, where CLASS is one
4661 of `PseudoColor', `TrueColor' etc. and DEPTH is the color
4662 depth, a decimal number. NAME is compared with case ignored. */
4663 char *s
= alloca (SBYTES (value
) + 1);
4668 lispstpcpy (s
, value
);
4669 dash
= strchr (s
, '-');
4672 dpyinfo
->n_planes
= atoi (dash
+ 1);
4676 /* We won't find a matching visual with depth 0, so that
4677 an error will be printed below. */
4678 dpyinfo
->n_planes
= 0;
4680 /* Determine the visual class. */
4681 for (i
= 0; visual_classes
[i
].name
; ++i
)
4682 if (xstrcasecmp (s
, visual_classes
[i
].name
) == 0)
4684 class = visual_classes
[i
].class;
4688 /* Look up a matching visual for the specified class. */
4690 || !XMatchVisualInfo (dpy
, XScreenNumberOfScreen (screen
),
4691 dpyinfo
->n_planes
, class, &vinfo
))
4692 fatal ("Invalid visual specification '%s'",
4693 SSDATA (ENCODE_SYSTEM (value
)));
4695 dpyinfo
->visual
= vinfo
.visual
;
4700 XVisualInfo
*vinfo
, vinfo_template
;
4702 dpyinfo
->visual
= DefaultVisualOfScreen (screen
);
4704 vinfo_template
.visualid
= XVisualIDFromVisual (dpyinfo
->visual
);
4705 vinfo_template
.screen
= XScreenNumberOfScreen (screen
);
4706 vinfo
= XGetVisualInfo (dpy
, VisualIDMask
| VisualScreenMask
,
4707 &vinfo_template
, &n_visuals
);
4709 fatal ("Can't get proper X visual info");
4711 dpyinfo
->n_planes
= vinfo
->depth
;
4717 /* Return the X display structure for the display named NAME.
4718 Open a new connection if necessary. */
4720 static struct x_display_info
*
4721 x_display_info_for_name (Lisp_Object name
)
4723 struct x_display_info
*dpyinfo
;
4725 CHECK_STRING (name
);
4727 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
4728 if (!NILP (Fstring_equal (XCAR (dpyinfo
->name_list_element
), name
)))
4731 /* Use this general default value to start with. */
4732 Vx_resource_name
= Vinvocation_name
;
4734 validate_x_resource_name ();
4736 dpyinfo
= x_term_init (name
, 0, SSDATA (Vx_resource_name
));
4739 error ("Cannot connect to X server %s", SDATA (name
));
4741 XSETFASTINT (Vwindow_system_version
, 11);
4747 DEFUN ("x-open-connection", Fx_open_connection
, Sx_open_connection
,
4749 doc
: /* Open a connection to a display server.
4750 DISPLAY is the name of the display to connect to.
4751 Optional second arg XRM-STRING is a string of resources in xrdb format.
4752 If the optional third arg MUST-SUCCEED is non-nil,
4753 terminate Emacs if we can't open the connection.
4754 (In the Nextstep version, the last two arguments are currently ignored.) */)
4755 (Lisp_Object display
, Lisp_Object xrm_string
, Lisp_Object must_succeed
)
4758 struct x_display_info
*dpyinfo
;
4760 CHECK_STRING (display
);
4761 if (! NILP (xrm_string
))
4762 CHECK_STRING (xrm_string
);
4764 xrm_option
= NILP (xrm_string
) ? 0 : SSDATA (xrm_string
);
4766 validate_x_resource_name ();
4768 /* This is what opens the connection and sets x_current_display.
4769 This also initializes many symbols, such as those used for input. */
4770 dpyinfo
= x_term_init (display
, xrm_option
,
4771 SSDATA (Vx_resource_name
));
4775 if (!NILP (must_succeed
))
4776 fatal ("Cannot connect to X server %s.\n\
4777 Check the DISPLAY environment variable or use `-d'.\n\
4778 Also use the `xauth' program to verify that you have the proper\n\
4779 authorization information needed to connect the X server.\n\
4780 An insecure way to solve the problem may be to use `xhost'.\n",
4783 error ("Cannot connect to X server %s", SDATA (display
));
4786 XSETFASTINT (Vwindow_system_version
, 11);
4790 DEFUN ("x-close-connection", Fx_close_connection
,
4791 Sx_close_connection
, 1, 1, 0,
4792 doc
: /* Close the connection to TERMINAL's X server.
4793 For TERMINAL, specify a terminal object, a frame or a display name (a
4794 string). If TERMINAL is nil, that stands for the selected frame's
4796 (Lisp_Object terminal
)
4798 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
4800 if (dpyinfo
->reference_count
> 0)
4801 error ("Display still has frames on it");
4803 x_delete_terminal (dpyinfo
->terminal
);
4808 DEFUN ("x-display-list", Fx_display_list
, Sx_display_list
, 0, 0, 0,
4809 doc
: /* Return the list of display names that Emacs has connections to. */)
4812 Lisp_Object result
= Qnil
;
4813 struct x_display_info
*xdi
;
4815 for (xdi
= x_display_list
; xdi
; xdi
= xdi
->next
)
4816 result
= Fcons (XCAR (xdi
->name_list_element
), result
);
4821 DEFUN ("x-synchronize", Fx_synchronize
, Sx_synchronize
, 1, 2, 0,
4822 doc
: /* If ON is non-nil, report X errors as soon as the erring request is made.
4823 This function only has an effect on X Windows. With MS Windows, it is
4824 defined but does nothing.
4826 If ON is nil, allow buffering of requests.
4827 Turning on synchronization prohibits the Xlib routines from buffering
4828 requests and seriously degrades performance, but makes debugging much
4830 The optional second argument TERMINAL specifies which display to act on.
4831 TERMINAL should be a terminal object, a frame or a display name (a string).
4832 If TERMINAL is omitted or nil, that stands for the selected frame's display. */)
4833 (Lisp_Object on
, Lisp_Object terminal
)
4835 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
4837 XSynchronize (dpyinfo
->display
, !EQ (on
, Qnil
));
4842 /* Wait for responses to all X commands issued so far for frame F. */
4845 x_sync (struct frame
*f
)
4848 XSync (FRAME_X_DISPLAY (f
), False
);
4853 /***********************************************************************
4855 ***********************************************************************/
4857 DEFUN ("x-change-window-property", Fx_change_window_property
,
4858 Sx_change_window_property
, 2, 6, 0,
4859 doc
: /* Change window property PROP to VALUE on the X window of FRAME.
4860 PROP must be a string. VALUE may be a string or a list of conses,
4861 numbers and/or strings. If an element in the list is a string, it is
4862 converted to an atom and the value of the atom is used. If an element
4863 is a cons, it is converted to a 32 bit number where the car is the 16
4864 top bits and the cdr is the lower 16 bits.
4866 FRAME nil or omitted means use the selected frame.
4867 If TYPE is given and non-nil, it is the name of the type of VALUE.
4868 If TYPE is not given or nil, the type is STRING.
4869 FORMAT gives the size in bits of each element if VALUE is a list.
4870 It must be one of 8, 16 or 32.
4871 If VALUE is a string or FORMAT is nil or not given, FORMAT defaults to 8.
4872 If OUTER-P is non-nil, the property is changed for the outer X window of
4873 FRAME. Default is to change on the edit X window. */)
4874 (Lisp_Object prop
, Lisp_Object value
, Lisp_Object frame
,
4875 Lisp_Object type
, Lisp_Object format
, Lisp_Object outer_p
)
4877 struct frame
*f
= decode_window_system_frame (frame
);
4879 Atom target_type
= XA_STRING
;
4880 int element_format
= 8;
4881 unsigned char *data
;
4885 CHECK_STRING (prop
);
4887 if (! NILP (format
))
4889 CHECK_NUMBER (format
);
4891 if (XINT (format
) != 8 && XINT (format
) != 16
4892 && XINT (format
) != 32)
4893 error ("FORMAT must be one of 8, 16 or 32");
4894 element_format
= XINT (format
);
4901 nelements
= x_check_property_data (value
);
4902 if (nelements
== -1)
4903 error ("Bad data in VALUE, must be number, string or cons");
4905 /* The man page for XChangeProperty:
4906 "If the specified format is 32, the property data must be a
4908 This applies even if long is more than 32 bits. The X library
4909 converts to 32 bits before sending to the X server. */
4910 elsize
= element_format
== 32 ? sizeof (long) : element_format
>> 3;
4911 data
= xnmalloc (nelements
, elsize
);
4913 x_fill_property_data (FRAME_X_DISPLAY (f
), value
, data
, element_format
);
4917 CHECK_STRING (value
);
4918 data
= SDATA (value
);
4919 if (INT_MAX
< SBYTES (value
))
4920 error ("VALUE too long");
4921 nelements
= SBYTES (value
);
4925 prop_atom
= XInternAtom (FRAME_X_DISPLAY (f
), SSDATA (prop
), False
);
4928 CHECK_STRING (type
);
4929 target_type
= XInternAtom (FRAME_X_DISPLAY (f
), SSDATA (type
), False
);
4932 if (! NILP (outer_p
)) w
= FRAME_OUTER_WINDOW (f
);
4933 else w
= FRAME_X_WINDOW (f
);
4935 XChangeProperty (FRAME_X_DISPLAY (f
), w
,
4936 prop_atom
, target_type
, element_format
, PropModeReplace
,
4939 if (CONSP (value
)) xfree (data
);
4941 /* Make sure the property is set when we return. */
4942 XFlush (FRAME_X_DISPLAY (f
));
4949 DEFUN ("x-delete-window-property", Fx_delete_window_property
,
4950 Sx_delete_window_property
, 1, 2, 0,
4951 doc
: /* Remove window property PROP from X window of FRAME.
4952 FRAME nil or omitted means use the selected frame. Value is PROP. */)
4953 (Lisp_Object prop
, Lisp_Object frame
)
4955 struct frame
*f
= decode_window_system_frame (frame
);
4958 CHECK_STRING (prop
);
4960 prop_atom
= XInternAtom (FRAME_X_DISPLAY (f
), SSDATA (prop
), False
);
4961 XDeleteProperty (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), prop_atom
);
4963 /* Make sure the property is removed when we return. */
4964 XFlush (FRAME_X_DISPLAY (f
));
4972 x_window_property_intern (struct frame
*f
,
4973 Window target_window
,
4976 Lisp_Object delete_p
,
4977 Lisp_Object vector_ret_p
,
4980 unsigned char *tmp_data
= NULL
;
4981 Lisp_Object prop_value
= Qnil
;
4984 unsigned long actual_size
, bytes_remaining
;
4987 rc
= XGetWindowProperty (FRAME_X_DISPLAY (f
), target_window
,
4988 prop_atom
, 0, 0, False
, target_type
,
4989 &actual_type
, &actual_format
, &actual_size
,
4990 &bytes_remaining
, &tmp_data
);
4992 *found
= actual_format
!= 0;
4994 if (rc
== Success
&& *found
)
4999 rc
= XGetWindowProperty (FRAME_X_DISPLAY (f
), target_window
,
5000 prop_atom
, 0, bytes_remaining
,
5001 ! NILP (delete_p
), target_type
,
5002 &actual_type
, &actual_format
,
5003 &actual_size
, &bytes_remaining
,
5005 if (rc
== Success
&& tmp_data
)
5007 /* The man page for XGetWindowProperty says:
5008 "If the returned format is 32, the returned data is represented
5009 as a long array and should be cast to that type to obtain the
5011 This applies even if long is more than 32 bits, the X library
5012 converts from 32 bit elements received from the X server to long
5013 and passes the long array to us. Thus, for that case memcpy can not
5014 be used. We convert to a 32 bit type here, because so much code
5017 The bytes and offsets passed to XGetWindowProperty refers to the
5018 property and those are indeed in 32 bit quantities if format is
5021 if (BITS_PER_LONG
> 32 && actual_format
== 32)
5024 int *idata
= (int *) tmp_data
;
5025 long *ldata
= (long *) tmp_data
;
5027 for (i
= 0; i
< actual_size
; ++i
)
5028 idata
[i
] = (int) ldata
[i
];
5031 if (NILP (vector_ret_p
))
5032 prop_value
= make_string ((char *) tmp_data
, actual_size
);
5034 prop_value
= x_property_data_to_lisp (f
,
5041 if (tmp_data
) XFree (tmp_data
);
5047 DEFUN ("x-window-property", Fx_window_property
, Sx_window_property
,
5049 doc
: /* Value is the value of window property PROP on FRAME.
5050 If FRAME is nil or omitted, use the selected frame.
5052 On X Windows, the following optional arguments are also accepted:
5053 If TYPE is nil or omitted, get the property as a string.
5054 Otherwise TYPE is the name of the atom that denotes the type expected.
5055 If SOURCE is non-nil, get the property on that window instead of from
5056 FRAME. The number 0 denotes the root window.
5057 If DELETE-P is non-nil, delete the property after retrieving it.
5058 If VECTOR-RET-P is non-nil, don't return a string but a vector of values.
5060 On MS Windows, this function accepts but ignores those optional arguments.
5062 Value is nil if FRAME hasn't a property with name PROP or if PROP has
5063 no value of TYPE (always string in the MS Windows case). */)
5064 (Lisp_Object prop
, Lisp_Object frame
, Lisp_Object type
,
5065 Lisp_Object source
, Lisp_Object delete_p
, Lisp_Object vector_ret_p
)
5067 struct frame
*f
= decode_window_system_frame (frame
);
5069 Lisp_Object prop_value
= Qnil
;
5070 Atom target_type
= XA_STRING
;
5071 Window target_window
= FRAME_X_WINDOW (f
);
5074 CHECK_STRING (prop
);
5076 if (! NILP (source
))
5078 CONS_TO_INTEGER (source
, Window
, target_window
);
5079 if (! target_window
)
5080 target_window
= FRAME_DISPLAY_INFO (f
)->root_window
;
5086 if (strcmp ("AnyPropertyType", SSDATA (type
)) == 0)
5087 target_type
= AnyPropertyType
;
5089 target_type
= XInternAtom (FRAME_X_DISPLAY (f
), SSDATA (type
), False
);
5092 prop_atom
= XInternAtom (FRAME_X_DISPLAY (f
), SSDATA (prop
), False
);
5093 prop_value
= x_window_property_intern (f
,
5100 if (NILP (prop_value
)
5103 && target_window
!= FRAME_OUTER_WINDOW (f
))
5105 prop_value
= x_window_property_intern (f
,
5106 FRAME_OUTER_WINDOW (f
),
5119 /***********************************************************************
5121 ***********************************************************************/
5123 static Lisp_Object
x_create_tip_frame (struct x_display_info
*,
5124 Lisp_Object
, Lisp_Object
);
5125 static void compute_tip_xy (struct frame
*, Lisp_Object
, Lisp_Object
,
5126 Lisp_Object
, int, int, int *, int *);
5128 /* The frame of a currently visible tooltip. */
5130 Lisp_Object tip_frame
;
5132 /* If non-nil, a timer started that hides the last tooltip when it
5135 static Lisp_Object tip_timer
;
5138 /* If non-nil, a vector of 3 elements containing the last args
5139 with which x-show-tip was called. See there. */
5141 static Lisp_Object last_show_tip_args
;
5145 unwind_create_tip_frame (Lisp_Object frame
)
5147 Lisp_Object deleted
;
5149 deleted
= unwind_create_frame (frame
);
5150 if (EQ (deleted
, Qt
))
5158 /* Create a frame for a tooltip on the display described by DPYINFO.
5159 PARMS is a list of frame parameters. TEXT is the string to
5160 display in the tip frame. Value is the frame.
5162 Note that functions called here, esp. x_default_parameter can
5163 signal errors, for instance when a specified color name is
5164 undefined. We have to make sure that we're in a consistent state
5165 when this happens. */
5168 x_create_tip_frame (struct x_display_info
*dpyinfo
,
5176 ptrdiff_t count
= SPECPDL_INDEX ();
5177 bool face_change_before
= face_change
;
5179 struct buffer
*old_buffer
;
5180 int x_width
= 0, x_height
= 0;
5182 if (!dpyinfo
->terminal
->name
)
5183 error ("Terminal is not live, can't create new frames on it");
5185 parms
= Fcopy_alist (parms
);
5187 /* Get the name of the frame to use for resource lookup. */
5188 name
= x_get_arg (dpyinfo
, parms
, Qname
, "name", "Name", RES_TYPE_STRING
);
5190 && !EQ (name
, Qunbound
)
5192 error ("Invalid frame name--not a string or nil");
5195 f
= make_frame (true);
5196 XSETFRAME (frame
, f
);
5198 AUTO_STRING (tip
, " *tip*");
5199 buffer
= Fget_buffer_create (tip
);
5200 /* Use set_window_buffer instead of Fset_window_buffer (see
5201 discussion of bug#11984, bug#12025, bug#12026). */
5202 set_window_buffer (FRAME_ROOT_WINDOW (f
), buffer
, false, false);
5203 old_buffer
= current_buffer
;
5204 set_buffer_internal_1 (XBUFFER (buffer
));
5205 bset_truncate_lines (current_buffer
, Qnil
);
5206 specbind (Qinhibit_read_only
, Qt
);
5207 specbind (Qinhibit_modification_hooks
, Qt
);
5210 set_buffer_internal_1 (old_buffer
);
5212 record_unwind_protect (unwind_create_tip_frame
, frame
);
5214 f
->terminal
= dpyinfo
->terminal
;
5216 /* By setting the output method, we're essentially saying that
5217 the frame is live, as per FRAME_LIVE_P. If we get a signal
5218 from this point on, x_destroy_window might screw up reference
5220 f
->output_method
= output_x_window
;
5221 f
->output_data
.x
= xzalloc (sizeof *f
->output_data
.x
);
5222 f
->output_data
.x
->icon_bitmap
= -1;
5223 FRAME_FONTSET (f
) = -1;
5224 f
->output_data
.x
->scroll_bar_foreground_pixel
= -1;
5225 f
->output_data
.x
->scroll_bar_background_pixel
= -1;
5226 #if defined (USE_LUCID) && defined (USE_TOOLKIT_SCROLL_BARS)
5227 f
->output_data
.x
->scroll_bar_top_shadow_pixel
= -1;
5228 f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
= -1;
5229 #endif /* USE_LUCID && USE_TOOLKIT_SCROLL_BARS */
5230 f
->output_data
.x
->white_relief
.pixel
= -1;
5231 f
->output_data
.x
->black_relief
.pixel
= -1;
5233 fset_icon_name (f
, Qnil
);
5234 FRAME_DISPLAY_INFO (f
) = dpyinfo
;
5235 f
->output_data
.x
->parent_desc
= FRAME_DISPLAY_INFO (f
)->root_window
;
5236 f
->output_data
.x
->explicit_parent
= false;
5238 /* These colors will be set anyway later, but it's important
5239 to get the color reference counts right, so initialize them! */
5243 /* Function x_decode_color can signal an error. Make
5244 sure to initialize color slots so that we won't try
5245 to free colors we haven't allocated. */
5246 FRAME_FOREGROUND_PIXEL (f
) = -1;
5247 FRAME_BACKGROUND_PIXEL (f
) = -1;
5248 f
->output_data
.x
->cursor_pixel
= -1;
5249 f
->output_data
.x
->cursor_foreground_pixel
= -1;
5250 f
->output_data
.x
->border_pixel
= -1;
5251 f
->output_data
.x
->mouse_pixel
= -1;
5253 black
= build_string ("black");
5254 FRAME_FOREGROUND_PIXEL (f
)
5255 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
5256 FRAME_BACKGROUND_PIXEL (f
)
5257 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
5258 f
->output_data
.x
->cursor_pixel
5259 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
5260 f
->output_data
.x
->cursor_foreground_pixel
5261 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
5262 f
->output_data
.x
->border_pixel
5263 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
5264 f
->output_data
.x
->mouse_pixel
5265 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
5268 /* Set the name; the functions to which we pass f expect the name to
5270 if (EQ (name
, Qunbound
) || NILP (name
))
5272 fset_name (f
, build_string (dpyinfo
->x_id_name
));
5273 f
->explicit_name
= false;
5277 fset_name (f
, name
);
5278 f
->explicit_name
= true;
5279 /* use the frame's title when getting resources for this frame. */
5280 specbind (Qx_resource_name
, name
);
5284 register_font_driver (&ftcrfont_driver
, f
);
5286 register_font_driver (&xfont_driver
, f
);
5287 #ifdef HAVE_FREETYPE
5289 register_font_driver (&xftfont_driver
, f
);
5290 #else /* not HAVE_XFT */
5291 register_font_driver (&ftxfont_driver
, f
);
5292 #endif /* not HAVE_XFT */
5293 #endif /* HAVE_FREETYPE */
5294 #endif /* not USE_CAIRO */
5296 image_cache_refcount
=
5297 FRAME_IMAGE_CACHE (f
) ? FRAME_IMAGE_CACHE (f
)->refcount
: 0;
5299 dpyinfo_refcount
= dpyinfo
->reference_count
;
5300 #endif /* GLYPH_DEBUG */
5302 x_default_parameter (f
, parms
, Qfont_backend
, Qnil
,
5303 "fontBackend", "FontBackend", RES_TYPE_STRING
);
5305 /* Extract the window parameters from the supplied values that are
5306 needed to determine window geometry. */
5307 x_default_font_parameter (f
, parms
);
5309 x_default_parameter (f
, parms
, Qborder_width
, make_number (0),
5310 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
5312 /* This defaults to 2 in order to match xterm. We recognize either
5313 internalBorderWidth or internalBorder (which is what xterm calls
5315 if (NILP (Fassq (Qinternal_border_width
, parms
)))
5319 value
= x_get_arg (dpyinfo
, parms
, Qinternal_border_width
,
5320 "internalBorder", "internalBorder", RES_TYPE_NUMBER
);
5321 if (! EQ (value
, Qunbound
))
5322 parms
= Fcons (Fcons (Qinternal_border_width
, value
),
5326 x_default_parameter (f
, parms
, Qinternal_border_width
, make_number (1),
5327 "internalBorderWidth", "internalBorderWidth",
5329 x_default_parameter (f
, parms
, Qright_divider_width
, make_number (0),
5330 NULL
, NULL
, RES_TYPE_NUMBER
);
5331 x_default_parameter (f
, parms
, Qbottom_divider_width
, make_number (0),
5332 NULL
, NULL
, RES_TYPE_NUMBER
);
5334 /* Also do the stuff which must be set before the window exists. */
5335 x_default_parameter (f
, parms
, Qforeground_color
, build_string ("black"),
5336 "foreground", "Foreground", RES_TYPE_STRING
);
5337 x_default_parameter (f
, parms
, Qbackground_color
, build_string ("white"),
5338 "background", "Background", RES_TYPE_STRING
);
5339 x_default_parameter (f
, parms
, Qmouse_color
, build_string ("black"),
5340 "pointerColor", "Foreground", RES_TYPE_STRING
);
5341 x_default_parameter (f
, parms
, Qcursor_color
, build_string ("black"),
5342 "cursorColor", "Foreground", RES_TYPE_STRING
);
5343 x_default_parameter (f
, parms
, Qborder_color
, build_string ("black"),
5344 "borderColor", "BorderColor", RES_TYPE_STRING
);
5346 /* Init faces before x_default_parameter is called for the
5347 scroll-bar-width parameter because otherwise we end up in
5348 init_iterator with a null face cache, which should not happen. */
5349 init_frame_faces (f
);
5351 f
->output_data
.x
->parent_desc
= FRAME_DISPLAY_INFO (f
)->root_window
;
5353 x_figure_window_size (f
, parms
, false, &x_width
, &x_height
);
5356 XSetWindowAttributes attrs
;
5358 Atom type
= FRAME_DISPLAY_INFO (f
)->Xatom_net_window_type_tooltip
;
5361 mask
= CWBackPixel
| CWOverrideRedirect
| CWEventMask
| CWCursor
;
5362 if (DoesSaveUnders (dpyinfo
->screen
))
5363 mask
|= CWSaveUnder
;
5365 /* Window managers look at the override-redirect flag to determine
5366 whether or net to give windows a decoration (Xlib spec, chapter
5368 attrs
.override_redirect
= True
;
5369 attrs
.save_under
= True
;
5370 attrs
.background_pixel
= FRAME_BACKGROUND_PIXEL (f
);
5372 f
->output_data
.x
->current_cursor
5373 = f
->output_data
.x
->text_cursor
;
5374 /* Arrange for getting MapNotify and UnmapNotify events. */
5375 attrs
.event_mask
= StructureNotifyMask
;
5377 = FRAME_X_WINDOW (f
)
5378 = XCreateWindow (FRAME_X_DISPLAY (f
),
5379 FRAME_DISPLAY_INFO (f
)->root_window
,
5380 /* x, y, width, height */
5384 CopyFromParent
, InputOutput
, CopyFromParent
,
5386 XChangeProperty (FRAME_X_DISPLAY (f
), tip_window
,
5387 FRAME_DISPLAY_INFO (f
)->Xatom_net_window_type
,
5388 XA_ATOM
, 32, PropModeReplace
,
5389 (unsigned char *)&type
, 1);
5395 x_default_parameter (f
, parms
, Qauto_raise
, Qnil
,
5396 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
5397 x_default_parameter (f
, parms
, Qauto_lower
, Qnil
,
5398 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
5399 x_default_parameter (f
, parms
, Qcursor_type
, Qbox
,
5400 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
5402 /* Dimensions, especially FRAME_LINES (f), must be done via change_frame_size.
5403 Change will not be effected unless different from the current
5405 width
= FRAME_COLS (f
);
5406 height
= FRAME_LINES (f
);
5407 SET_FRAME_COLS (f
, 0);
5408 SET_FRAME_LINES (f
, 0);
5409 change_frame_size (f
, width
, height
, true, false, false, false);
5411 /* Add `tooltip' frame parameter's default value. */
5412 if (NILP (Fframe_parameter (frame
, Qtooltip
)))
5414 AUTO_FRAME_ARG (arg
, Qtooltip
, Qt
);
5415 Fmodify_frame_parameters (frame
, arg
);
5418 /* FIXME - can this be done in a similar way to normal frames?
5419 http://lists.gnu.org/archive/html/emacs-devel/2007-10/msg00641.html */
5421 /* Set the `display-type' frame parameter before setting up faces. */
5423 Lisp_Object disptype
;
5425 if (FRAME_DISPLAY_INFO (f
)->n_planes
== 1)
5427 else if (FRAME_DISPLAY_INFO (f
)->visual
->class == GrayScale
5428 || FRAME_DISPLAY_INFO (f
)->visual
->class == StaticGray
)
5429 disptype
= intern ("grayscale");
5431 disptype
= intern ("color");
5433 if (NILP (Fframe_parameter (frame
, Qdisplay_type
)))
5435 AUTO_FRAME_ARG (arg
, Qdisplay_type
, disptype
);
5436 Fmodify_frame_parameters (frame
, arg
);
5440 /* Set up faces after all frame parameters are known. This call
5441 also merges in face attributes specified for new frames.
5443 Frame parameters may be changed if .Xdefaults contains
5444 specifications for the default font. For example, if there is an
5445 `Emacs.default.attributeBackground: pink', the `background-color'
5446 attribute of the frame get's set, which let's the internal border
5447 of the tooltip frame appear in pink. Prevent this. */
5449 Lisp_Object bg
= Fframe_parameter (frame
, Qbackground_color
);
5451 /* Set tip_frame here, so that */
5453 call2 (Qface_set_after_frame_default
, frame
, Qnil
);
5455 if (!EQ (bg
, Fframe_parameter (frame
, Qbackground_color
)))
5457 AUTO_FRAME_ARG (arg
, Qbackground_color
, bg
);
5458 Fmodify_frame_parameters (frame
, arg
);
5464 /* Now that the frame will be official, it counts as a reference to
5465 its display and terminal. */
5466 FRAME_DISPLAY_INFO (f
)->reference_count
++;
5467 f
->terminal
->reference_count
++;
5469 /* It is now ok to make the frame official even if we get an error
5470 below. And the frame needs to be on Vframe_list or making it
5471 visible won't work. */
5472 Vframe_list
= Fcons (frame
, Vframe_list
);
5473 f
->can_x_set_window_size
= true;
5475 /* Setting attributes of faces of the tooltip frame from resources
5476 and similar will set face_change, which leads to the clearing of
5477 all current matrices. Since this isn't necessary here, avoid it
5478 by resetting face_change to the value it had before we created
5480 face_change
= face_change_before
;
5482 /* Discard the unwind_protect. */
5483 return unbind_to (count
, frame
);
5487 /* Compute where to display tip frame F. PARMS is the list of frame
5488 parameters for F. DX and DY are specified offsets from the current
5489 location of the mouse. WIDTH and HEIGHT are the width and height
5490 of the tooltip. Return coordinates relative to the root window of
5491 the display in *ROOT_X, and *ROOT_Y. */
5494 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
)
5496 Lisp_Object left
, top
, right
, bottom
;
5501 /* User-specified position? */
5502 left
= Fcdr (Fassq (Qleft
, parms
));
5503 top
= Fcdr (Fassq (Qtop
, parms
));
5504 right
= Fcdr (Fassq (Qright
, parms
));
5505 bottom
= Fcdr (Fassq (Qbottom
, parms
));
5507 /* Move the tooltip window where the mouse pointer is. Resize and
5509 if ((!INTEGERP (left
) && !INTEGERP (right
))
5510 || (!INTEGERP (top
) && !INTEGERP (bottom
)))
5513 XQueryPointer (FRAME_X_DISPLAY (f
), FRAME_DISPLAY_INFO (f
)->root_window
,
5514 &root
, &child
, root_x
, root_y
, &win_x
, &win_y
, &pmask
);
5519 *root_y
= XINT (top
);
5520 else if (INTEGERP (bottom
))
5521 *root_y
= XINT (bottom
) - height
;
5522 else if (*root_y
+ XINT (dy
) <= 0)
5523 *root_y
= 0; /* Can happen for negative dy */
5524 else if (*root_y
+ XINT (dy
) + height
5525 <= x_display_pixel_height (FRAME_DISPLAY_INFO (f
)))
5526 /* It fits below the pointer */
5527 *root_y
+= XINT (dy
);
5528 else if (height
+ XINT (dy
) <= *root_y
)
5529 /* It fits above the pointer. */
5530 *root_y
-= height
+ XINT (dy
);
5532 /* Put it on the top. */
5535 if (INTEGERP (left
))
5536 *root_x
= XINT (left
);
5537 else if (INTEGERP (right
))
5538 *root_y
= XINT (right
) - width
;
5539 else if (*root_x
+ XINT (dx
) <= 0)
5540 *root_x
= 0; /* Can happen for negative dx */
5541 else if (*root_x
+ XINT (dx
) + width
5542 <= x_display_pixel_width (FRAME_DISPLAY_INFO (f
)))
5543 /* It fits to the right of the pointer. */
5544 *root_x
+= XINT (dx
);
5545 else if (width
+ XINT (dx
) <= *root_x
)
5546 /* It fits to the left of the pointer. */
5547 *root_x
-= width
+ XINT (dx
);
5549 /* Put it left-justified on the screen--it ought to fit that way. */
5554 DEFUN ("x-show-tip", Fx_show_tip
, Sx_show_tip
, 1, 6, 0,
5555 doc
: /* Show STRING in a "tooltip" window on frame FRAME.
5556 A tooltip window is a small X window displaying a string.
5558 This is an internal function; Lisp code should call `tooltip-show'.
5560 FRAME nil or omitted means use the selected frame.
5562 PARMS is an optional list of frame parameters which can be used to
5563 change the tooltip's appearance.
5565 Automatically hide the tooltip after TIMEOUT seconds. TIMEOUT nil
5566 means use the default timeout of 5 seconds.
5568 If the list of frame parameters PARMS contains a `left' parameter,
5569 display the tooltip at that x-position. If the list of frame parameters
5570 PARMS contains no `left' but a `right' parameter, display the tooltip
5571 right-adjusted at that x-position. Otherwise display it at the
5572 x-position of the mouse, with offset DX added (default is 5 if DX isn't
5575 Likewise for the y-position: If a `top' frame parameter is specified, it
5576 determines the position of the upper edge of the tooltip window. If a
5577 `bottom' parameter but no `top' frame parameter is specified, it
5578 determines the position of the lower edge of the tooltip window.
5579 Otherwise display the tooltip window at the y-position of the mouse,
5580 with offset DY added (default is -10).
5582 A tooltip's maximum size is specified by `x-max-tooltip-size'.
5583 Text larger than the specified size is clipped. */)
5584 (Lisp_Object string
, Lisp_Object frame
, Lisp_Object parms
, Lisp_Object timeout
, Lisp_Object dx
, Lisp_Object dy
)
5589 struct buffer
*old_buffer
;
5590 struct text_pos pos
;
5591 int i
, width
, height
;
5592 bool seen_reversed_p
;
5593 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
5594 ptrdiff_t count
= SPECPDL_INDEX ();
5596 specbind (Qinhibit_redisplay
, Qt
);
5598 CHECK_STRING (string
);
5599 if (SCHARS (string
) == 0)
5600 string
= make_unibyte_string (" ", 1);
5602 f
= decode_window_system_frame (frame
);
5604 timeout
= make_number (5);
5606 CHECK_NATNUM (timeout
);
5609 dx
= make_number (5);
5614 dy
= make_number (-10);
5619 if (x_gtk_use_system_tooltips
)
5623 /* Hide a previous tip, if any. */
5627 ok
= xg_prepare_tooltip (f
, string
, &width
, &height
);
5630 compute_tip_xy (f
, parms
, dx
, dy
, width
, height
, &root_x
, &root_y
);
5631 xg_show_tooltip (f
, root_x
, root_y
);
5632 /* This is used in Fx_hide_tip. */
5633 XSETFRAME (tip_frame
, f
);
5636 if (ok
) goto start_timer
;
5638 #endif /* USE_GTK */
5640 if (NILP (last_show_tip_args
))
5641 last_show_tip_args
= Fmake_vector (make_number (3), Qnil
);
5643 if (!NILP (tip_frame
))
5645 Lisp_Object last_string
= AREF (last_show_tip_args
, 0);
5646 Lisp_Object last_frame
= AREF (last_show_tip_args
, 1);
5647 Lisp_Object last_parms
= AREF (last_show_tip_args
, 2);
5649 if (EQ (frame
, last_frame
)
5650 && !NILP (Fequal (last_string
, string
))
5651 && !NILP (Fequal (last_parms
, parms
)))
5653 struct frame
*tip_f
= XFRAME (tip_frame
);
5655 /* Only DX and DY have changed. */
5656 if (!NILP (tip_timer
))
5658 Lisp_Object timer
= tip_timer
;
5660 call1 (Qcancel_timer
, timer
);
5664 compute_tip_xy (tip_f
, parms
, dx
, dy
, FRAME_PIXEL_WIDTH (tip_f
),
5665 FRAME_PIXEL_HEIGHT (tip_f
), &root_x
, &root_y
);
5666 XMoveWindow (FRAME_X_DISPLAY (tip_f
), FRAME_X_WINDOW (tip_f
),
5673 /* Hide a previous tip, if any. */
5676 ASET (last_show_tip_args
, 0, string
);
5677 ASET (last_show_tip_args
, 1, frame
);
5678 ASET (last_show_tip_args
, 2, parms
);
5680 /* Add default values to frame parameters. */
5681 if (NILP (Fassq (Qname
, parms
)))
5682 parms
= Fcons (Fcons (Qname
, build_string ("tooltip")), parms
);
5683 if (NILP (Fassq (Qinternal_border_width
, parms
)))
5684 parms
= Fcons (Fcons (Qinternal_border_width
, make_number (3)), parms
);
5685 if (NILP (Fassq (Qborder_width
, parms
)))
5686 parms
= Fcons (Fcons (Qborder_width
, make_number (1)), parms
);
5687 if (NILP (Fassq (Qbottom_divider_width
, parms
)))
5688 parms
= Fcons (Fcons (Qbottom_divider_width
, make_number (0)), parms
);
5689 if (NILP (Fassq (Qright_divider_width
, parms
)))
5690 parms
= Fcons (Fcons (Qright_divider_width
, make_number (0)), parms
);
5691 if (NILP (Fassq (Qborder_color
, parms
)))
5692 parms
= Fcons (Fcons (Qborder_color
, build_string ("lightyellow")), parms
);
5693 if (NILP (Fassq (Qbackground_color
, parms
)))
5694 parms
= Fcons (Fcons (Qbackground_color
, build_string ("lightyellow")),
5697 /* Create a frame for the tooltip, and record it in the global
5698 variable tip_frame. */
5699 frame
= x_create_tip_frame (FRAME_DISPLAY_INFO (f
), parms
, string
);
5702 /* Set up the frame's root window. */
5703 w
= XWINDOW (FRAME_ROOT_WINDOW (f
));
5709 if (CONSP (Vx_max_tooltip_size
)
5710 && RANGED_INTEGERP (1, XCAR (Vx_max_tooltip_size
), INT_MAX
)
5711 && RANGED_INTEGERP (1, XCDR (Vx_max_tooltip_size
), INT_MAX
))
5713 w
->total_cols
= XFASTINT (XCAR (Vx_max_tooltip_size
));
5714 w
->total_lines
= XFASTINT (XCDR (Vx_max_tooltip_size
));
5719 w
->total_lines
= 40;
5722 w
->pixel_width
= w
->total_cols
* FRAME_COLUMN_WIDTH (f
);
5723 w
->pixel_height
= w
->total_lines
* FRAME_LINE_HEIGHT (f
);
5725 FRAME_TOTAL_COLS (f
) = w
->total_cols
;
5726 adjust_frame_glyphs (f
);
5727 w
->pseudo_window_p
= true;
5729 /* Display the tooltip text in a temporary buffer. */
5730 old_buffer
= current_buffer
;
5731 set_buffer_internal_1 (XBUFFER (XWINDOW (FRAME_ROOT_WINDOW (f
))->contents
));
5732 bset_truncate_lines (current_buffer
, Qnil
);
5733 clear_glyph_matrix (w
->desired_matrix
);
5734 clear_glyph_matrix (w
->current_matrix
);
5735 SET_TEXT_POS (pos
, BEGV
, BEGV_BYTE
);
5736 try_window (FRAME_ROOT_WINDOW (f
), pos
, TRY_WINDOW_IGNORE_FONTS_CHANGE
);
5738 /* Compute width and height of the tooltip. */
5740 seen_reversed_p
= false;
5741 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
5743 struct glyph_row
*row
= &w
->desired_matrix
->rows
[i
];
5747 /* Stop at the first empty row at the end. */
5748 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
5751 /* Let the row go over the full width of the frame. */
5752 row
->full_width_p
= true;
5754 row_width
= row
->pixel_width
;
5755 if (row
->used
[TEXT_AREA
])
5757 /* There's a glyph at the end of rows that is used to place
5758 the cursor there. Don't include the width of this glyph. */
5759 if (!row
->reversed_p
)
5761 last
= &row
->glyphs
[TEXT_AREA
][row
->used
[TEXT_AREA
] - 1];
5762 if (NILP (last
->object
))
5763 row_width
-= last
->pixel_width
;
5767 /* There could be a stretch glyph at the beginning of R2L
5768 rows that is produced by extend_face_to_end_of_line.
5769 Don't count that glyph. */
5770 struct glyph
*g
= row
->glyphs
[TEXT_AREA
];
5772 if (g
->type
== STRETCH_GLYPH
&& NILP (g
->object
))
5774 row_width
-= g
->pixel_width
;
5775 seen_reversed_p
= true;
5780 height
+= row
->height
;
5781 width
= max (width
, row_width
);
5784 /* If we've seen partial-length R2L rows, we need to re-adjust the
5785 tool-tip frame width and redisplay it again, to avoid over-wide
5786 tips due to the stretch glyph that extends R2L lines to full
5787 width of the frame. */
5788 if (seen_reversed_p
)
5790 /* w->total_cols and FRAME_TOTAL_COLS want the width in columns,
5792 w
->pixel_width
= width
;
5793 width
/= WINDOW_FRAME_COLUMN_WIDTH (w
);
5794 w
->total_cols
= width
;
5795 FRAME_TOTAL_COLS (f
) = width
;
5796 SET_FRAME_WIDTH (f
, width
);
5797 adjust_frame_glyphs (f
);
5798 clear_glyph_matrix (w
->desired_matrix
);
5799 clear_glyph_matrix (w
->current_matrix
);
5800 try_window (FRAME_ROOT_WINDOW (f
), pos
, 0);
5802 /* Recompute width and height of the tooltip. */
5803 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
5805 struct glyph_row
*row
= &w
->desired_matrix
->rows
[i
];
5809 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
5811 row
->full_width_p
= true;
5812 row_width
= row
->pixel_width
;
5813 if (row
->used
[TEXT_AREA
] && !row
->reversed_p
)
5815 last
= &row
->glyphs
[TEXT_AREA
][row
->used
[TEXT_AREA
] - 1];
5816 if (NILP (last
->object
))
5817 row_width
-= last
->pixel_width
;
5820 height
+= row
->height
;
5821 width
= max (width
, row_width
);
5825 /* Add the frame's internal border to the width and height the X
5826 window should have. */
5827 height
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
5828 width
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
5830 /* Move the tooltip window where the mouse pointer is. Resize and
5832 compute_tip_xy (f
, parms
, dx
, dy
, width
, height
, &root_x
, &root_y
);
5835 XMoveResizeWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5836 root_x
, root_y
, width
, height
);
5837 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
5840 /* Draw into the window. */
5841 w
->must_be_updated_p
= true;
5842 update_single_window (w
);
5844 /* Restore original current buffer. */
5845 set_buffer_internal_1 (old_buffer
);
5846 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
5849 /* Let the tip disappear after timeout seconds. */
5850 tip_timer
= call3 (intern ("run-at-time"), timeout
, Qnil
,
5851 intern ("x-hide-tip"));
5853 return unbind_to (count
, Qnil
);
5857 DEFUN ("x-hide-tip", Fx_hide_tip
, Sx_hide_tip
, 0, 0, 0,
5858 doc
: /* Hide the current tooltip window, if there is any.
5859 Value is t if tooltip was open, nil otherwise. */)
5863 Lisp_Object deleted
, frame
, timer
;
5865 /* Return quickly if nothing to do. */
5866 if (NILP (tip_timer
) && NILP (tip_frame
))
5871 tip_frame
= tip_timer
= deleted
= Qnil
;
5873 count
= SPECPDL_INDEX ();
5874 specbind (Qinhibit_redisplay
, Qt
);
5875 specbind (Qinhibit_quit
, Qt
);
5878 call1 (Qcancel_timer
, timer
);
5882 /* When using system tooltip, tip_frame is the Emacs frame on which
5883 the tip is shown. */
5884 struct frame
*f
= XFRAME (frame
);
5885 if (FRAME_LIVE_P (f
) && xg_hide_tooltip (f
))
5892 delete_frame (frame
, Qnil
);
5896 /* Bloodcurdling hack alert: The Lucid menu bar widget's
5897 redisplay procedure is not called when a tip frame over menu
5898 items is unmapped. Redisplay the menu manually... */
5901 struct frame
*f
= SELECTED_FRAME ();
5902 w
= f
->output_data
.x
->menubar_widget
;
5904 if (!DoesSaveUnders (FRAME_DISPLAY_INFO (f
)->screen
)
5908 xlwmenu_redisplay (w
);
5912 #endif /* USE_LUCID */
5915 return unbind_to (count
, deleted
);
5920 /***********************************************************************
5921 File selection dialog
5922 ***********************************************************************/
5924 DEFUN ("x-uses-old-gtk-dialog", Fx_uses_old_gtk_dialog
,
5925 Sx_uses_old_gtk_dialog
,
5927 doc
: /* Return t if the old Gtk+ file selection dialog is used. */)
5933 && window_system_available (SELECTED_FRAME ())
5934 && xg_uses_old_file_dialog ())
5942 /* Callback for "OK" and "Cancel" on file selection dialog. */
5945 file_dialog_cb (Widget widget
, XtPointer client_data
, XtPointer call_data
)
5947 int *result
= client_data
;
5948 XmAnyCallbackStruct
*cb
= call_data
;
5949 *result
= cb
->reason
;
5953 /* Callback for unmapping a file selection dialog. This is used to
5954 capture the case where a dialog is closed via a window manager's
5955 closer button, for example. Using a XmNdestroyCallback didn't work
5959 file_dialog_unmap_cb (Widget widget
, XtPointer client_data
, XtPointer call_data
)
5961 int *result
= client_data
;
5962 *result
= XmCR_CANCEL
;
5966 clean_up_file_dialog (void *arg
)
5968 Widget dialog
= arg
;
5972 XtUnmanageChild (dialog
);
5973 XtDestroyWidget (dialog
);
5974 x_menu_set_in_use (false);
5979 DEFUN ("x-file-dialog", Fx_file_dialog
, Sx_file_dialog
, 2, 5, 0,
5980 doc
: /* Read file name, prompting with PROMPT in directory DIR.
5981 Use a file selection dialog. Select DEFAULT-FILENAME in the dialog's file
5982 selection box, if specified. If MUSTMATCH is non-nil, the returned file
5983 or directory must exist.
5985 This function is only defined on NS, MS Windows, and X Windows with the
5986 Motif or Gtk toolkits. With the Motif toolkit, ONLY-DIR-P is ignored.
5987 Otherwise, if ONLY-DIR-P is non-nil, the user can only select directories.
5988 On Windows 7 and later, the file selection dialog "remembers" the last
5989 directory where the user selected a file, and will open that directory
5990 instead of DIR on subsequent invocations of this function with the same
5991 value of DIR as in previous invocations; this is standard Windows behavior. */)
5992 (Lisp_Object prompt
, Lisp_Object dir
, Lisp_Object default_filename
,
5993 Lisp_Object mustmatch
, Lisp_Object only_dir_p
)
5996 struct frame
*f
= SELECTED_FRAME ();
5997 Lisp_Object file
= Qnil
;
5998 Lisp_Object decoded_file
;
5999 Widget dialog
, text
, help
;
6002 XmString dir_xmstring
, pattern_xmstring
;
6003 ptrdiff_t count
= SPECPDL_INDEX ();
6005 check_window_system (f
);
6007 if (popup_activated ())
6008 error ("Trying to use a menu from within a menu-entry");
6010 CHECK_STRING (prompt
);
6013 /* Prevent redisplay. */
6014 specbind (Qinhibit_redisplay
, Qt
);
6018 /* Create the dialog with PROMPT as title, using DIR as initial
6019 directory and using "*" as pattern. */
6020 dir
= Fexpand_file_name (dir
, Qnil
);
6021 dir_xmstring
= XmStringCreateLocalized (SSDATA (dir
));
6022 pattern_xmstring
= XmStringCreateLocalized ("*");
6024 XtSetArg (al
[ac
], XmNtitle
, SDATA (prompt
)); ++ac
;
6025 XtSetArg (al
[ac
], XmNdirectory
, dir_xmstring
); ++ac
;
6026 XtSetArg (al
[ac
], XmNpattern
, pattern_xmstring
); ++ac
;
6027 XtSetArg (al
[ac
], XmNresizePolicy
, XmRESIZE_GROW
); ++ac
;
6028 XtSetArg (al
[ac
], XmNdialogStyle
, XmDIALOG_APPLICATION_MODAL
); ++ac
;
6029 dialog
= XmCreateFileSelectionDialog (f
->output_data
.x
->widget
,
6031 XmStringFree (dir_xmstring
);
6032 XmStringFree (pattern_xmstring
);
6034 /* Add callbacks for OK and Cancel. */
6035 XtAddCallback (dialog
, XmNokCallback
, file_dialog_cb
,
6036 (XtPointer
) &result
);
6037 XtAddCallback (dialog
, XmNcancelCallback
, file_dialog_cb
,
6038 (XtPointer
) &result
);
6039 XtAddCallback (dialog
, XmNunmapCallback
, file_dialog_unmap_cb
,
6040 (XtPointer
) &result
);
6042 /* Remove the help button since we can't display help. */
6043 help
= XmFileSelectionBoxGetChild (dialog
, XmDIALOG_HELP_BUTTON
);
6044 XtUnmanageChild (help
);
6046 /* Mark OK button as default. */
6047 XtVaSetValues (XmFileSelectionBoxGetChild (dialog
, XmDIALOG_OK_BUTTON
),
6048 XmNshowAsDefault
, True
, NULL
);
6050 /* If MUSTMATCH is non-nil, disable the file entry field of the
6051 dialog, so that the user must select a file from the files list
6052 box. We can't remove it because we wouldn't have a way to get at
6053 the result file name, then. */
6054 text
= XmFileSelectionBoxGetChild (dialog
, XmDIALOG_TEXT
);
6055 if (!NILP (mustmatch
))
6058 label
= XmFileSelectionBoxGetChild (dialog
, XmDIALOG_SELECTION_LABEL
);
6059 XtSetSensitive (text
, False
);
6060 XtSetSensitive (label
, False
);
6063 /* Manage the dialog, so that list boxes get filled. */
6064 XtManageChild (dialog
);
6066 if (STRINGP (default_filename
))
6068 XmString default_xmstring
;
6069 Widget wtext
= XmFileSelectionBoxGetChild (dialog
, XmDIALOG_TEXT
);
6070 Widget list
= XmFileSelectionBoxGetChild (dialog
, XmDIALOG_LIST
);
6072 XmTextPosition last_pos
= XmTextFieldGetLastPosition (wtext
);
6073 XmTextFieldReplace (wtext
, 0, last_pos
,
6074 (SSDATA (Ffile_name_nondirectory (default_filename
))));
6076 /* Select DEFAULT_FILENAME in the files list box. DEFAULT_FILENAME
6077 must include the path for this to work. */
6079 default_xmstring
= XmStringCreateLocalized (SSDATA (default_filename
));
6081 if (XmListItemExists (list
, default_xmstring
))
6083 int item_pos
= XmListItemPos (list
, default_xmstring
);
6084 /* Select the item and scroll it into view. */
6085 XmListSelectPos (list
, item_pos
, True
);
6086 XmListSetPos (list
, item_pos
);
6089 XmStringFree (default_xmstring
);
6092 record_unwind_protect_ptr (clean_up_file_dialog
, dialog
);
6094 /* Process events until the user presses Cancel or OK. */
6095 x_menu_set_in_use (true);
6100 x_menu_wait_for_event (0);
6101 XtAppNextEvent (Xt_app_con
, &event
);
6102 if (event
.type
== KeyPress
6103 && FRAME_X_DISPLAY (f
) == event
.xkey
.display
)
6105 KeySym keysym
= XLookupKeysym (&event
.xkey
, 0);
6107 /* Pop down on C-g. */
6108 if (keysym
== XK_g
&& (event
.xkey
.state
& ControlMask
) != 0)
6109 XtUnmanageChild (dialog
);
6112 (void) x_dispatch_event (&event
, FRAME_X_DISPLAY (f
));
6115 /* Get the result. */
6116 if (result
== XmCR_OK
)
6118 XmString text_string
;
6121 XtVaGetValues (dialog
, XmNtextString
, &text_string
, NULL
);
6122 XmStringGetLtoR (text_string
, XmFONTLIST_DEFAULT_TAG
, &data
);
6123 XmStringFree (text_string
);
6124 file
= build_string (data
);
6132 /* Make "Cancel" equivalent to C-g. */
6134 Fsignal (Qquit
, Qnil
);
6136 decoded_file
= DECODE_FILE (file
);
6138 return unbind_to (count
, decoded_file
);
6141 #endif /* USE_MOTIF */
6146 clean_up_dialog (void)
6148 x_menu_set_in_use (false);
6151 DEFUN ("x-file-dialog", Fx_file_dialog
, Sx_file_dialog
, 2, 5, 0,
6152 doc
: /* Read file name, prompting with PROMPT in directory DIR.
6153 Use a file selection dialog. Select DEFAULT-FILENAME in the dialog's file
6154 selection box, if specified. If MUSTMATCH is non-nil, the returned file
6155 or directory must exist.
6157 This function is only defined on NS, MS Windows, and X Windows with the
6158 Motif or Gtk toolkits. With the Motif toolkit, ONLY-DIR-P is ignored.
6159 Otherwise, if ONLY-DIR-P is non-nil, the user can only select directories.
6160 On Windows 7 and later, the file selection dialog "remembers" the last
6161 directory where the user selected a file, and will open that directory
6162 instead of DIR on subsequent invocations of this function with the same
6163 value of DIR as in previous invocations; this is standard Windows behavior. */)
6164 (Lisp_Object prompt
, Lisp_Object dir
, Lisp_Object default_filename
, Lisp_Object mustmatch
, Lisp_Object only_dir_p
)
6166 struct frame
*f
= SELECTED_FRAME ();
6168 Lisp_Object file
= Qnil
;
6169 Lisp_Object decoded_file
;
6170 ptrdiff_t count
= SPECPDL_INDEX ();
6173 check_window_system (f
);
6175 if (popup_activated ())
6176 error ("Trying to use a menu from within a menu-entry");
6178 CHECK_STRING (prompt
);
6181 /* Prevent redisplay. */
6182 specbind (Qinhibit_redisplay
, Qt
);
6183 record_unwind_protect_void (clean_up_dialog
);
6187 if (STRINGP (default_filename
))
6188 cdef_file
= SSDATA (default_filename
);
6190 cdef_file
= SSDATA (dir
);
6192 fn
= xg_get_file_name (f
, SSDATA (prompt
), cdef_file
,
6194 ! NILP (only_dir_p
));
6198 file
= build_string (fn
);
6204 /* Make "Cancel" equivalent to C-g. */
6206 Fsignal (Qquit
, Qnil
);
6208 decoded_file
= DECODE_FILE (file
);
6210 return unbind_to (count
, decoded_file
);
6214 #ifdef HAVE_FREETYPE
6216 DEFUN ("x-select-font", Fx_select_font
, Sx_select_font
, 0, 2, 0,
6217 doc
: /* Read a font using a GTK dialog.
6218 Return either a font spec (for GTK versions >= 3.2) or a string
6219 containing a GTK-style font name.
6221 FRAME is the frame on which to pop up the font chooser. If omitted or
6222 nil, it defaults to the selected frame. */)
6223 (Lisp_Object frame
, Lisp_Object ignored
)
6225 struct frame
*f
= decode_window_system_frame (frame
);
6227 Lisp_Object font_param
;
6228 char *default_name
= NULL
;
6229 ptrdiff_t count
= SPECPDL_INDEX ();
6231 if (popup_activated ())
6232 error ("Trying to use a menu from within a menu-entry");
6234 /* Prevent redisplay. */
6235 specbind (Qinhibit_redisplay
, Qt
);
6236 record_unwind_protect_void (clean_up_dialog
);
6240 XSETFONT (font
, FRAME_FONT (f
));
6241 font_param
= Ffont_get (font
, QCname
);
6242 if (STRINGP (font_param
))
6243 default_name
= xlispstrdup (font_param
);
6246 font_param
= Fframe_parameter (frame
, Qfont_param
);
6247 if (STRINGP (font_param
))
6248 default_name
= xlispstrdup (font_param
);
6251 font
= xg_get_font (f
, default_name
);
6252 xfree (default_name
);
6257 Fsignal (Qquit
, Qnil
);
6259 return unbind_to (count
, font
);
6261 #endif /* HAVE_FREETYPE */
6263 #endif /* USE_GTK */
6266 /***********************************************************************
6268 ***********************************************************************/
6271 #include <X11/XKBlib.h>
6272 #include <X11/keysym.h>
6275 DEFUN ("x-backspace-delete-keys-p", Fx_backspace_delete_keys_p
,
6276 Sx_backspace_delete_keys_p
, 0, 1, 0,
6277 doc
: /* Check if both Backspace and Delete keys are on the keyboard of FRAME.
6278 FRAME nil means use the selected frame.
6279 Value is t if we know that both keys are present, and are mapped to the
6280 usual X keysyms. Value is `lambda' if we cannot determine if both keys are
6281 present and mapped to the usual X keysyms. */)
6288 struct frame
*f
= decode_window_system_frame (frame
);
6289 Display
*dpy
= FRAME_X_DISPLAY (f
);
6290 Lisp_Object have_keys
;
6291 int major
, minor
, op
, event
, error_code
;
6295 /* Check library version in case we're dynamically linked. */
6296 major
= XkbMajorVersion
;
6297 minor
= XkbMinorVersion
;
6298 if (!XkbLibraryVersion (&major
, &minor
))
6304 /* Check that the server supports XKB. */
6305 major
= XkbMajorVersion
;
6306 minor
= XkbMinorVersion
;
6307 if (!XkbQueryExtension (dpy
, &op
, &event
, &error_code
, &major
, &minor
))
6313 /* In this code we check that the keyboard has physical keys with names
6314 that start with BKSP (Backspace) and DELE (Delete), and that they
6315 generate keysym XK_BackSpace and XK_Delete respectively.
6316 This function is used to test if normal-erase-is-backspace should be
6318 An alternative approach would be to just check if XK_BackSpace and
6319 XK_Delete are mapped to any key. But if any of those are mapped to
6320 some non-intuitive key combination (Meta-Shift-Ctrl-whatever) and the
6321 user doesn't know about it, it is better to return false here.
6322 It is more obvious to the user what to do if she/he has two keys
6323 clearly marked with names/symbols and one key does something not
6324 expected (i.e. she/he then tries the other).
6325 The cases where Backspace/Delete is mapped to some other key combination
6326 are rare, and in those cases, normal-erase-is-backspace can be turned on
6330 kb
= XkbGetMap (dpy
, XkbAllMapComponentsMask
, XkbUseCoreKbd
);
6333 int delete_keycode
= 0, backspace_keycode
= 0, i
;
6335 if (XkbGetNames (dpy
, XkbAllNamesMask
, kb
) == Success
)
6337 for (i
= kb
->min_key_code
;
6338 (i
< kb
->max_key_code
6339 && (delete_keycode
== 0 || backspace_keycode
== 0));
6342 /* The XKB symbolic key names can be seen most easily in
6343 the PS file generated by `xkbprint -label name
6345 if (memcmp ("DELE", kb
->names
->keys
[i
].name
, 4) == 0)
6347 else if (memcmp ("BKSP", kb
->names
->keys
[i
].name
, 4) == 0)
6348 backspace_keycode
= i
;
6351 XkbFreeNames (kb
, 0, True
);
6354 /* As of libX11-1.6.2, XkbGetMap manual says that you should use
6355 XkbFreeClientMap to free the data returned by XkbGetMap. But
6356 this function just frees the data referenced from KB and not
6357 KB itself. To free KB as well, call XkbFreeKeyboard. */
6358 XkbFreeKeyboard (kb
, XkbAllMapComponentsMask
, True
);
6361 && backspace_keycode
6362 && XKeysymToKeycode (dpy
, XK_Delete
) == delete_keycode
6363 && XKeysymToKeycode (dpy
, XK_BackSpace
) == backspace_keycode
)
6373 /***********************************************************************
6375 ***********************************************************************/
6378 DEFUN ("x-export-frames", Fx_export_frames
, Sx_export_frames
, 0, 2, 0,
6379 doc
: /* XXX Experimental. Return image data of FRAMES in TYPE format.
6380 FRAMES should be nil (the selected frame), a frame, or a list of
6381 frames (each of which corresponds to one page). Optional arg TYPE
6382 should be either `pdf' (default), `png', `ps', or `svg'. Supported
6383 types are determined by the compile-time configuration of cairo. */)
6384 (Lisp_Object frames
, Lisp_Object type
)
6386 Lisp_Object result
, rest
, tmp
;
6387 cairo_surface_type_t surface_type
;
6390 frames
= selected_frame
;
6391 if (!CONSP (frames
))
6392 frames
= list1 (frames
);
6395 for (rest
= frames
; CONSP (rest
); rest
= XCDR (rest
))
6397 struct frame
*f
= XFRAME (XCAR (rest
));
6399 if (! FRAME_LIVE_P (f
) || ! FRAME_X_P (f
) || ! FRAME_LIVE_P (f
))
6400 error ("Invalid frame");
6404 XSETFRAME (frame
, f
);
6405 tmp
= Fcons (frame
, tmp
);
6407 frames
= Fnreverse (tmp
);
6409 #ifdef CAIRO_HAS_PDF_SURFACE
6410 if (NILP (type
) || EQ (type
, intern ("pdf"))) /* XXX: Qpdf */
6411 surface_type
= CAIRO_SURFACE_TYPE_PDF
;
6414 #ifdef CAIRO_HAS_PNG_FUNCTIONS
6415 if (EQ (type
, intern ("png")))
6417 if (!NILP (XCDR (frames
)))
6418 error ("PNG export cannot handle multiple frames.");
6419 surface_type
= CAIRO_SURFACE_TYPE_IMAGE
;
6423 #ifdef CAIRO_HAS_PS_SURFACE
6424 if (EQ (type
, intern ("ps")))
6425 surface_type
= CAIRO_SURFACE_TYPE_PS
;
6428 #ifdef CAIRO_HAS_SVG_SURFACE
6429 if (EQ (type
, intern ("svg")))
6431 /* For now, we stick to SVG 1.1. */
6432 if (!NILP (XCDR (frames
)))
6433 error ("SVG export cannot handle multiple frames.");
6434 surface_type
= CAIRO_SURFACE_TYPE_SVG
;
6438 error ("Unsupported export type");
6440 result
= x_cr_export_frames (frames
, surface_type
);
6446 DEFUN ("x-page-setup-dialog", Fx_page_setup_dialog
, Sx_page_setup_dialog
, 0, 0, 0,
6447 doc
: /* Pop up a page setup dialog.
6448 The current page setup can be obtained using `x-get-page-setup'. */)
6452 xg_page_setup_dialog ();
6458 DEFUN ("x-get-page-setup", Fx_get_page_setup
, Sx_get_page_setup
, 0, 0, 0,
6459 doc
: /* Return the value of the current page setup.
6460 The return value is an alist containing the following keys:
6462 orientation: page orientation (symbol `portrait', `landscape',
6463 `reverse-portrait', or `reverse-landscape').
6464 width, height: page width/height in points not including margins.
6465 left-margin, right-margin, top-margin, bottom-margin: print margins,
6466 which is the parts of the page that the printer cannot print
6469 The paper width can be obtained as the sum of width, left-margin, and
6470 right-margin values. Likewise, the paper height is the sum of height,
6471 top-margin, and bottom-margin values. */)
6477 result
= xg_get_page_setup ();
6483 DEFUN ("x-print-frames-dialog", Fx_print_frames_dialog
, Sx_print_frames_dialog
, 0, 1, "",
6484 doc
: /* Pop up a print dialog to print the current contents of FRAMES.
6485 FRAMES should be nil (the selected frame), a frame, or a list of
6486 frames (each of which corresponds to one page). Each frame should be
6488 (Lisp_Object frames
)
6490 Lisp_Object rest
, tmp
;
6493 frames
= selected_frame
;
6494 if (!CONSP (frames
))
6495 frames
= list1 (frames
);
6498 for (rest
= frames
; CONSP (rest
); rest
= XCDR (rest
))
6500 struct frame
*f
= XFRAME (XCAR (rest
));
6501 if (! FRAME_LIVE_P (f
) || ! FRAME_X_P (f
) || ! FRAME_LIVE_P (f
))
6502 error ("Invalid frame");
6505 XSETFRAME (frame
, f
);
6506 if (!EQ (Fframe_visible_p (frame
), Qt
))
6507 error ("Frames to be printed must be visible.");
6508 tmp
= Fcons (frame
, tmp
);
6510 frames
= Fnreverse (tmp
);
6512 /* Make sure the current matrices are up-to-date. */
6516 xg_print_frames_dialog (frames
);
6521 #endif /* USE_GTK */
6522 #endif /* USE_CAIRO */
6525 /***********************************************************************
6527 ***********************************************************************/
6529 /* Keep this list in the same order as frame_parms in frame.c.
6530 Use 0 for unsupported frame parameters. */
6532 frame_parm_handler x_frame_parm_handlers
[] =
6536 x_set_background_color
,
6542 x_set_foreground_color
,
6545 x_set_internal_border_width
,
6546 x_set_right_divider_width
,
6547 x_set_bottom_divider_width
,
6548 x_set_menu_bar_lines
,
6550 x_explicitly_set_name
,
6551 x_set_scroll_bar_width
,
6552 x_set_scroll_bar_height
,
6555 x_set_vertical_scroll_bars
,
6556 x_set_horizontal_scroll_bars
,
6558 x_set_tool_bar_lines
,
6559 x_set_scroll_bar_foreground
,
6560 x_set_scroll_bar_background
,
6570 x_set_tool_bar_position
,
6576 DEFSYM (Qundefined_color
, "undefined-color");
6577 DEFSYM (Qcompound_text
, "compound-text");
6578 DEFSYM (Qcancel_timer
, "cancel-timer");
6579 DEFSYM (Qfont_param
, "font-parameter");
6580 DEFSYM (Qmono
, "mono");
6583 DEFSYM (Qorientation
, "orientation");
6584 DEFSYM (Qtop_margin
, "top-margin");
6585 DEFSYM (Qbottom_margin
, "bottom-margin");
6586 DEFSYM (Qportrait
, "portrait");
6587 DEFSYM (Qlandscape
, "landscape");
6588 DEFSYM (Qreverse_portrait
, "reverse-portrait");
6589 DEFSYM (Qreverse_landscape
, "reverse-landscape");
6592 Fput (Qundefined_color
, Qerror_conditions
,
6593 listn (CONSTYPE_PURE
, 2, Qundefined_color
, Qerror
));
6594 Fput (Qundefined_color
, Qerror_message
,
6595 build_pure_c_string ("Undefined color"));
6597 DEFVAR_LISP ("x-pointer-shape", Vx_pointer_shape
,
6598 doc
: /* The shape of the pointer when over text.
6599 Changing the value does not affect existing frames
6600 unless you set the mouse color. */);
6601 Vx_pointer_shape
= Qnil
;
6603 #if false /* This doesn't really do anything. */
6604 DEFVAR_LISP ("x-nontext-pointer-shape", Vx_nontext_pointer_shape
,
6605 doc
: /* The shape of the pointer when not over text.
6606 This variable takes effect when you create a new frame
6607 or when you set the mouse color. */);
6609 Vx_nontext_pointer_shape
= Qnil
;
6611 DEFVAR_LISP ("x-hourglass-pointer-shape", Vx_hourglass_pointer_shape
,
6612 doc
: /* The shape of the pointer when Emacs is busy.
6613 This variable takes effect when you create a new frame
6614 or when you set the mouse color. */);
6615 Vx_hourglass_pointer_shape
= Qnil
;
6617 #if false /* This doesn't really do anything. */
6618 DEFVAR_LISP ("x-mode-pointer-shape", Vx_mode_pointer_shape
,
6619 doc
: /* The shape of the pointer when over the mode line.
6620 This variable takes effect when you create a new frame
6621 or when you set the mouse color. */);
6623 Vx_mode_pointer_shape
= Qnil
;
6625 DEFVAR_LISP ("x-sensitive-text-pointer-shape",
6626 Vx_sensitive_text_pointer_shape
,
6627 doc
: /* The shape of the pointer when over mouse-sensitive text.
6628 This variable takes effect when you create a new frame
6629 or when you set the mouse color. */);
6630 Vx_sensitive_text_pointer_shape
= Qnil
;
6632 DEFVAR_LISP ("x-window-horizontal-drag-cursor",
6633 Vx_window_horizontal_drag_shape
,
6634 doc
: /* Pointer shape to use for indicating a window can be dragged horizontally.
6635 This variable takes effect when you create a new frame
6636 or when you set the mouse color. */);
6637 Vx_window_horizontal_drag_shape
= Qnil
;
6639 DEFVAR_LISP ("x-window-vertical-drag-cursor",
6640 Vx_window_vertical_drag_shape
,
6641 doc
: /* Pointer shape to use for indicating a window can be dragged vertically.
6642 This variable takes effect when you create a new frame
6643 or when you set the mouse color. */);
6644 Vx_window_vertical_drag_shape
= Qnil
;
6646 DEFVAR_LISP ("x-cursor-fore-pixel", Vx_cursor_fore_pixel
,
6647 doc
: /* A string indicating the foreground color of the cursor box. */);
6648 Vx_cursor_fore_pixel
= Qnil
;
6650 DEFVAR_LISP ("x-max-tooltip-size", Vx_max_tooltip_size
,
6651 doc
: /* Maximum size for tooltips.
6652 Value is a pair (COLUMNS . ROWS). Text larger than this is clipped. */);
6653 Vx_max_tooltip_size
= Fcons (make_number (80), make_number (40));
6655 DEFVAR_LISP ("x-no-window-manager", Vx_no_window_manager
,
6656 doc
: /* Non-nil if no X window manager is in use.
6657 Emacs doesn't try to figure this out; this is always nil
6658 unless you set it to something else. */);
6659 /* We don't have any way to find this out, so set it to nil
6660 and maybe the user would like to set it to t. */
6661 Vx_no_window_manager
= Qnil
;
6663 DEFVAR_LISP ("x-pixel-size-width-font-regexp",
6664 Vx_pixel_size_width_font_regexp
,
6665 doc
: /* Regexp matching a font name whose width is the same as `PIXEL_SIZE'.
6667 Since Emacs gets width of a font matching with this regexp from
6668 PIXEL_SIZE field of the name, font finding mechanism gets faster for
6669 such a font. This is especially effective for such large fonts as
6670 Chinese, Japanese, and Korean. */);
6671 Vx_pixel_size_width_font_regexp
= Qnil
;
6673 /* This is not ifdef:ed, so other builds than GTK can customize it. */
6674 DEFVAR_BOOL ("x-gtk-use-old-file-dialog", x_gtk_use_old_file_dialog
,
6675 doc
: /* Non-nil means prompt with the old GTK file selection dialog.
6676 If nil or if the file selection dialog is not available, the new GTK file
6677 chooser is used instead. To turn off all file dialogs set the
6678 variable `use-file-dialog'. */);
6679 x_gtk_use_old_file_dialog
= false;
6681 DEFVAR_BOOL ("x-gtk-show-hidden-files", x_gtk_show_hidden_files
,
6682 doc
: /* If non-nil, the GTK file chooser will by default show hidden files.
6683 Note that this is just the default, there is a toggle button on the file
6684 chooser to show or not show hidden files on a case by case basis. */);
6685 x_gtk_show_hidden_files
= false;
6687 DEFVAR_BOOL ("x-gtk-file-dialog-help-text", x_gtk_file_dialog_help_text
,
6688 doc
: /* If non-nil, the GTK file chooser will show additional help text.
6689 If more space for files in the file chooser dialog is wanted, set this to nil
6690 to turn the additional text off. */);
6691 x_gtk_file_dialog_help_text
= true;
6693 DEFVAR_BOOL ("x-gtk-use-system-tooltips", x_gtk_use_system_tooltips
,
6694 doc
: /* If non-nil with a Gtk+ built Emacs, the Gtk+ tooltip is used.
6695 Otherwise use Emacs own tooltip implementation.
6696 When using Gtk+ tooltips, the tooltip face is not used. */);
6697 x_gtk_use_system_tooltips
= true;
6699 /* Tell Emacs about this window system. */
6700 Fprovide (Qx
, Qnil
);
6702 #ifdef USE_X_TOOLKIT
6703 Fprovide (intern_c_string ("x-toolkit"), Qnil
);
6705 Fprovide (intern_c_string ("motif"), Qnil
);
6707 DEFVAR_LISP ("motif-version-string", Vmotif_version_string
,
6708 doc
: /* Version info for LessTif/Motif. */);
6709 Vmotif_version_string
= build_string (XmVERSION_STRING
);
6710 #endif /* USE_MOTIF */
6711 #endif /* USE_X_TOOLKIT */
6714 /* Provide x-toolkit also for GTK. Internally GTK does not use Xt so it
6715 is not an X toolkit in that sense (USE_X_TOOLKIT is not defined).
6716 But for a user it is a toolkit for X, and indeed, configure
6717 accepts --with-x-toolkit=gtk. */
6718 Fprovide (intern_c_string ("x-toolkit"), Qnil
);
6719 Fprovide (intern_c_string ("gtk"), Qnil
);
6720 Fprovide (intern_c_string ("move-toolbar"), Qnil
);
6722 DEFVAR_LISP ("gtk-version-string", Vgtk_version_string
,
6723 doc
: /* Version info for GTK+. */);
6725 char gtk_version
[sizeof ".." + 3 * INT_STRLEN_BOUND (int)];
6726 int len
= sprintf (gtk_version
, "%d.%d.%d",
6727 GTK_MAJOR_VERSION
, GTK_MINOR_VERSION
, GTK_MICRO_VERSION
);
6728 Vgtk_version_string
= make_pure_string (gtk_version
, len
, len
, false);
6730 #endif /* USE_GTK */
6733 Fprovide (intern_c_string ("cairo"), Qnil
);
6735 DEFVAR_LISP ("cairo-version-string", Vcairo_version_string
,
6736 doc
: /* Version info for cairo. */);
6738 char cairo_version
[sizeof ".." + 3 * INT_STRLEN_BOUND (int)];
6739 int len
= sprintf (cairo_version
, "%d.%d.%d",
6740 CAIRO_VERSION_MAJOR
, CAIRO_VERSION_MINOR
,
6741 CAIRO_VERSION_MICRO
);
6742 Vcairo_version_string
= make_pure_string (cairo_version
, len
, len
, false);
6746 /* X window properties. */
6747 defsubr (&Sx_change_window_property
);
6748 defsubr (&Sx_delete_window_property
);
6749 defsubr (&Sx_window_property
);
6751 defsubr (&Sxw_display_color_p
);
6752 defsubr (&Sx_display_grayscale_p
);
6753 defsubr (&Sxw_color_defined_p
);
6754 defsubr (&Sxw_color_values
);
6755 defsubr (&Sx_server_max_request_size
);
6756 defsubr (&Sx_server_vendor
);
6757 defsubr (&Sx_server_version
);
6758 defsubr (&Sx_display_pixel_width
);
6759 defsubr (&Sx_display_pixel_height
);
6760 defsubr (&Sx_display_mm_width
);
6761 defsubr (&Sx_display_mm_height
);
6762 defsubr (&Sx_display_screens
);
6763 defsubr (&Sx_display_planes
);
6764 defsubr (&Sx_display_color_cells
);
6765 defsubr (&Sx_display_visual_class
);
6766 defsubr (&Sx_display_backing_store
);
6767 defsubr (&Sx_display_save_under
);
6768 defsubr (&Sx_display_monitor_attributes_list
);
6769 defsubr (&Sx_frame_geometry
);
6770 defsubr (&Sx_frame_edges
);
6771 defsubr (&Sx_mouse_absolute_pixel_position
);
6772 defsubr (&Sx_set_mouse_absolute_pixel_position
);
6773 defsubr (&Sx_wm_set_size_hint
);
6774 defsubr (&Sx_create_frame
);
6775 defsubr (&Sx_open_connection
);
6776 defsubr (&Sx_close_connection
);
6777 defsubr (&Sx_display_list
);
6778 defsubr (&Sx_synchronize
);
6779 defsubr (&Sx_backspace_delete_keys_p
);
6781 defsubr (&Sx_show_tip
);
6782 defsubr (&Sx_hide_tip
);
6784 staticpro (&tip_timer
);
6786 staticpro (&tip_frame
);
6788 last_show_tip_args
= Qnil
;
6789 staticpro (&last_show_tip_args
);
6791 defsubr (&Sx_uses_old_gtk_dialog
);
6792 #if defined (USE_MOTIF) || defined (USE_GTK)
6793 defsubr (&Sx_file_dialog
);
6796 #if defined (USE_GTK) && defined (HAVE_FREETYPE)
6797 defsubr (&Sx_select_font
);
6801 defsubr (&Sx_export_frames
);
6803 defsubr (&Sx_page_setup_dialog
);
6804 defsubr (&Sx_get_page_setup
);
6805 defsubr (&Sx_print_frames_dialog
);