1 /* Functions for the X window system.
2 Copyright (C) 1989, 1992, 1993, 1994, 1995 Free Software Foundation.
4 This file is part of GNU Emacs.
6 GNU Emacs is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Emacs is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Emacs; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
20 /* Completely rewritten by Richard Stallman. */
22 /* Rewritten for X11 by Joseph Arceneaux */
27 /* This makes the fields of a Display accessible, in Xlib header files. */
28 #define XLIB_ILLEGAL_ACCESS
35 #include "dispextern.h"
37 #include "blockinput.h"
44 #if 1 /* Used to be #ifdef EMACS_BITMAP_FILES, but this should always work. */
45 #include "bitmaps/gray.xbm"
47 #include <X11/bitmaps/gray>
50 #include "[.bitmaps]gray.xbm"
54 #include <X11/Shell.h>
56 #include <X11/Xaw/Paned.h>
57 #include <X11/Xaw/Label.h>
60 #undef USG /* ####KLUDGE for Solaris 2.2 and up */
69 #include "../lwlib/lwlib.h"
71 /* Do the EDITRES protocol if running X11R5 */
72 #if (XtSpecificationRelease >= 5)
74 extern void _XEditResCheckMessages ();
75 #endif /* R5 + Athena */
77 /* Unique id counter for widgets created by the Lucid Widget
79 extern LWLIB_ID widget_id_tick
;
81 /* This is part of a kludge--see lwlib/xlwmenu.c. */
82 XFontStruct
*xlwmenu_default_font
;
84 extern void free_frame_menubar ();
85 #endif /* USE_X_TOOLKIT */
87 #define min(a,b) ((a) < (b) ? (a) : (b))
88 #define max(a,b) ((a) > (b) ? (a) : (b))
91 #define MAXREQUEST(dpy) (XMaxRequestSize (dpy))
93 #define MAXREQUEST(dpy) ((dpy)->max_request_size)
96 /* The name we're using in resource queries. */
97 Lisp_Object Vx_resource_name
;
99 /* The background and shape of the mouse pointer, and shape when not
100 over text or in the modeline. */
101 Lisp_Object Vx_pointer_shape
, Vx_nontext_pointer_shape
, Vx_mode_pointer_shape
;
102 /* The shape when over mouse-sensitive text. */
103 Lisp_Object Vx_sensitive_text_pointer_shape
;
105 /* Color of chars displayed in cursor box. */
106 Lisp_Object Vx_cursor_fore_pixel
;
108 /* Nonzero if using X. */
111 /* Non nil if no window manager is in use. */
112 Lisp_Object Vx_no_window_manager
;
114 /* Search path for bitmap files. */
115 Lisp_Object Vx_bitmap_file_path
;
117 /* Evaluate this expression to rebuild the section of syms_of_xfns
118 that initializes and staticpros the symbols declared below. Note
119 that Emacs 18 has a bug that keeps C-x C-e from being able to
120 evaluate this expression.
123 ;; Accumulate a list of the symbols we want to initialize from the
124 ;; declarations at the top of the file.
125 (goto-char (point-min))
126 (search-forward "/\*&&& symbols declared here &&&*\/\n")
128 (while (looking-at "Lisp_Object \\(Q[a-z_]+\\)")
130 (cons (buffer-substring (match-beginning 1) (match-end 1))
133 (setq symbol-list (nreverse symbol-list))
134 ;; Delete the section of syms_of_... where we initialize the symbols.
135 (search-forward "\n /\*&&& init symbols here &&&*\/\n")
136 (let ((start (point)))
137 (while (looking-at "^ Q")
139 (kill-region start (point)))
140 ;; Write a new symbol initialization section.
142 (insert (format " %s = intern (\"" (car symbol-list)))
143 (let ((start (point)))
144 (insert (substring (car symbol-list) 1))
145 (subst-char-in-region start (point) ?_ ?-))
146 (insert (format "\");\n staticpro (&%s);\n" (car symbol-list)))
147 (setq symbol-list (cdr symbol-list)))))
151 /*&&& symbols declared here &&&*/
152 Lisp_Object Qauto_raise
;
153 Lisp_Object Qauto_lower
;
154 Lisp_Object Qbackground_color
;
156 Lisp_Object Qborder_color
;
157 Lisp_Object Qborder_width
;
159 Lisp_Object Qcursor_color
;
160 Lisp_Object Qcursor_type
;
162 Lisp_Object Qforeground_color
;
163 Lisp_Object Qgeometry
;
164 Lisp_Object Qicon_left
;
165 Lisp_Object Qicon_top
;
166 Lisp_Object Qicon_type
;
167 Lisp_Object Qinternal_border_width
;
169 Lisp_Object Qmouse_color
;
171 Lisp_Object Qparent_id
;
172 Lisp_Object Qscroll_bar_width
;
173 Lisp_Object Qsuppress_icon
;
175 Lisp_Object Qundefined_color
;
176 Lisp_Object Qvertical_scroll_bars
;
177 Lisp_Object Qvisibility
;
178 Lisp_Object Qwindow_id
;
179 Lisp_Object Qx_frame_parameter
;
180 Lisp_Object Qx_resource_name
;
181 Lisp_Object Quser_position
;
182 Lisp_Object Quser_size
;
183 Lisp_Object Qdisplay
;
185 /* The below are defined in frame.c. */
186 extern Lisp_Object Qheight
, Qminibuffer
, Qname
, Qonly
, Qwidth
;
187 extern Lisp_Object Qunsplittable
, Qmenu_bar_lines
;
189 extern Lisp_Object Vwindow_system_version
;
192 /* Error if we are not connected to X. */
197 error ("X windows are not in use or not initialized");
200 /* Nonzero if using X for display. */
208 /* Extract a frame as a FRAME_PTR, defaulting to the selected frame
209 and checking validity for X. */
212 check_x_frame (frame
)
221 CHECK_LIVE_FRAME (frame
, 0);
225 error ("non-X frame used");
229 /* Let the user specify an X display with a frame.
230 nil stands for the selected frame--or, if that is not an X frame,
231 the first X display on the list. */
233 static struct x_display_info
*
234 check_x_display_info (frame
)
239 if (FRAME_X_P (selected_frame
))
240 return FRAME_X_DISPLAY_INFO (selected_frame
);
241 else if (x_display_list
!= 0)
242 return x_display_list
;
244 error ("X windows are not in use or not initialized");
246 else if (STRINGP (frame
))
247 return x_display_info_for_name (frame
);
252 CHECK_LIVE_FRAME (frame
, 0);
255 error ("non-X frame used");
256 return FRAME_X_DISPLAY_INFO (f
);
260 /* Return the Emacs frame-object corresponding to an X window.
261 It could be the frame's main window or an icon window. */
263 /* This function can be called during GC, so use GC_xxx type test macros. */
266 x_window_to_frame (dpyinfo
, wdesc
)
267 struct x_display_info
*dpyinfo
;
270 Lisp_Object tail
, frame
;
273 for (tail
= Vframe_list
; GC_CONSP (tail
); tail
= XCONS (tail
)->cdr
)
275 frame
= XCONS (tail
)->car
;
276 if (!GC_FRAMEP (frame
))
279 if (f
->display
.nothing
== 1 || FRAME_X_DISPLAY_INFO (f
) != dpyinfo
)
282 if ((f
->display
.x
->edit_widget
283 && XtWindow (f
->display
.x
->edit_widget
) == wdesc
)
284 || f
->display
.x
->icon_desc
== wdesc
)
286 #else /* not USE_X_TOOLKIT */
287 if (FRAME_X_WINDOW (f
) == wdesc
288 || f
->display
.x
->icon_desc
== wdesc
)
290 #endif /* not USE_X_TOOLKIT */
296 /* Like x_window_to_frame but also compares the window with the widget's
300 x_any_window_to_frame (dpyinfo
, wdesc
)
301 struct x_display_info
*dpyinfo
;
304 Lisp_Object tail
, frame
;
308 for (tail
= Vframe_list
; GC_CONSP (tail
); tail
= XCONS (tail
)->cdr
)
310 frame
= XCONS (tail
)->car
;
311 if (!GC_FRAMEP (frame
))
314 if (f
->display
.nothing
== 1 || FRAME_X_DISPLAY_INFO (f
) != dpyinfo
)
317 /* This frame matches if the window is any of its widgets. */
318 if (wdesc
== XtWindow (x
->widget
)
319 || wdesc
== XtWindow (x
->column_widget
)
320 || wdesc
== XtWindow (x
->edit_widget
))
322 /* Match if the window is this frame's menubar. */
323 if (lw_window_is_in_menubar (wdesc
, x
->menubar_widget
))
329 /* Likewise, but exclude the menu bar widget. */
332 x_non_menubar_window_to_frame (dpyinfo
, wdesc
)
333 struct x_display_info
*dpyinfo
;
336 Lisp_Object tail
, frame
;
340 for (tail
= Vframe_list
; GC_CONSP (tail
); tail
= XCONS (tail
)->cdr
)
342 frame
= XCONS (tail
)->car
;
343 if (!GC_FRAMEP (frame
))
346 if (f
->display
.nothing
== 1 || FRAME_X_DISPLAY_INFO (f
) != dpyinfo
)
349 /* This frame matches if the window is any of its widgets. */
350 if (wdesc
== XtWindow (x
->widget
)
351 || wdesc
== XtWindow (x
->column_widget
)
352 || wdesc
== XtWindow (x
->edit_widget
))
358 /* Return the frame whose principal (outermost) window is WDESC.
359 If WDESC is some other (smaller) window, we return 0. */
362 x_top_window_to_frame (dpyinfo
, wdesc
)
363 struct x_display_info
*dpyinfo
;
366 Lisp_Object tail
, frame
;
370 for (tail
= Vframe_list
; GC_CONSP (tail
); tail
= XCONS (tail
)->cdr
)
372 frame
= XCONS (tail
)->car
;
373 if (!GC_FRAMEP (frame
))
376 if (f
->display
.nothing
== 1 || FRAME_X_DISPLAY_INFO (f
) != dpyinfo
)
379 /* This frame matches if the window is its topmost widget. */
380 if (wdesc
== XtWindow (x
->widget
))
382 /* Match if the window is this frame's menubar. */
383 if (x
->menubar_widget
384 && wdesc
== XtWindow (x
->menubar_widget
))
389 #endif /* USE_X_TOOLKIT */
393 /* Code to deal with bitmaps. Bitmaps are referenced by their bitmap
394 id, which is just an int that this section returns. Bitmaps are
395 reference counted so they can be shared among frames.
397 Bitmap indices are guaranteed to be > 0, so a negative number can
398 be used to indicate no bitmap.
400 If you use x_create_bitmap_from_data, then you must keep track of
401 the bitmaps yourself. That is, creating a bitmap from the same
402 data more than once will not be caught. */
405 /* Functions to access the contents of a bitmap, given an id. */
408 x_bitmap_height (f
, id
)
412 return FRAME_X_DISPLAY_INFO (f
)->bitmaps
[id
- 1].height
;
416 x_bitmap_width (f
, id
)
420 return FRAME_X_DISPLAY_INFO (f
)->bitmaps
[id
- 1].width
;
424 x_bitmap_pixmap (f
, id
)
428 return FRAME_X_DISPLAY_INFO (f
)->bitmaps
[id
- 1].pixmap
;
432 /* Allocate a new bitmap record. Returns index of new record. */
435 x_allocate_bitmap_record (f
)
438 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
441 if (dpyinfo
->bitmaps
== NULL
)
443 dpyinfo
->bitmaps_size
= 10;
445 = (struct x_bitmap_record
*) xmalloc (dpyinfo
->bitmaps_size
* sizeof (struct x_bitmap_record
));
446 dpyinfo
->bitmaps_last
= 1;
450 if (dpyinfo
->bitmaps_last
< dpyinfo
->bitmaps_size
)
451 return ++dpyinfo
->bitmaps_last
;
453 for (i
= 0; i
< dpyinfo
->bitmaps_size
; ++i
)
454 if (dpyinfo
->bitmaps
[i
].refcount
== 0)
457 dpyinfo
->bitmaps_size
*= 2;
459 = (struct x_bitmap_record
*) xrealloc (dpyinfo
->bitmaps
,
460 dpyinfo
->bitmaps_size
* sizeof (struct x_bitmap_record
));
461 return ++dpyinfo
->bitmaps_last
;
464 /* Add one reference to the reference count of the bitmap with id ID. */
467 x_reference_bitmap (f
, id
)
471 ++FRAME_X_DISPLAY_INFO (f
)->bitmaps
[id
- 1].refcount
;
474 /* Create a bitmap for frame F from a HEIGHT x WIDTH array of bits at BITS. */
477 x_create_bitmap_from_data (f
, bits
, width
, height
)
480 unsigned int width
, height
;
482 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
486 bitmap
= XCreateBitmapFromData (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
487 bits
, width
, height
);
492 id
= x_allocate_bitmap_record (f
);
493 dpyinfo
->bitmaps
[id
- 1].pixmap
= bitmap
;
494 dpyinfo
->bitmaps
[id
- 1].file
= NULL
;
495 dpyinfo
->bitmaps
[id
- 1].refcount
= 1;
496 dpyinfo
->bitmaps
[id
- 1].depth
= 1;
497 dpyinfo
->bitmaps
[id
- 1].height
= height
;
498 dpyinfo
->bitmaps
[id
- 1].width
= width
;
503 /* Create bitmap from file FILE for frame F. */
506 x_create_bitmap_from_file (f
, file
)
510 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
511 unsigned int width
, height
;
513 int xhot
, yhot
, result
, id
;
518 /* Look for an existing bitmap with the same name. */
519 for (id
= 0; id
< dpyinfo
->bitmaps_last
; ++id
)
521 if (dpyinfo
->bitmaps
[id
].refcount
522 && dpyinfo
->bitmaps
[id
].file
523 && !strcmp (dpyinfo
->bitmaps
[id
].file
, (char *) XSTRING (file
)->data
))
525 ++dpyinfo
->bitmaps
[id
].refcount
;
530 /* Search bitmap-file-path for the file, if appropriate. */
531 fd
= openp (Vx_bitmap_file_path
, file
, "", &found
, 0);
536 filename
= (char *) XSTRING (found
)->data
;
538 result
= XReadBitmapFile (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
539 filename
, &width
, &height
, &bitmap
, &xhot
, &yhot
);
540 if (result
!= BitmapSuccess
)
543 id
= x_allocate_bitmap_record (f
);
544 dpyinfo
->bitmaps
[id
- 1].pixmap
= bitmap
;
545 dpyinfo
->bitmaps
[id
- 1].refcount
= 1;
546 dpyinfo
->bitmaps
[id
- 1].file
= (char *) xmalloc (XSTRING (file
)->size
+ 1);
547 dpyinfo
->bitmaps
[id
- 1].depth
= 1;
548 dpyinfo
->bitmaps
[id
- 1].height
= height
;
549 dpyinfo
->bitmaps
[id
- 1].width
= width
;
550 strcpy (dpyinfo
->bitmaps
[id
- 1].file
, XSTRING (file
)->data
);
555 /* Remove reference to bitmap with id number ID. */
558 x_destroy_bitmap (f
, id
)
562 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
566 --dpyinfo
->bitmaps
[id
- 1].refcount
;
567 if (dpyinfo
->bitmaps
[id
- 1].refcount
== 0)
569 XFreePixmap (FRAME_X_DISPLAY (f
), dpyinfo
->bitmaps
[id
- 1].pixmap
);
570 if (dpyinfo
->bitmaps
[id
- 1].file
)
572 free (dpyinfo
->bitmaps
[id
- 1].file
);
573 dpyinfo
->bitmaps
[id
- 1].file
= NULL
;
579 /* Free all the bitmaps for the display specified by DPYINFO. */
582 x_destroy_all_bitmaps (dpyinfo
)
583 struct x_display_info
*dpyinfo
;
586 for (i
= 0; i
< dpyinfo
->bitmaps_last
; i
++)
587 if (dpyinfo
->bitmaps
[i
].refcount
> 0)
589 XFreePixmap (dpyinfo
->display
, dpyinfo
->bitmaps
[i
].pixmap
);
590 if (dpyinfo
->bitmaps
[i
].file
)
591 free (dpyinfo
->bitmaps
[i
].file
);
593 dpyinfo
->bitmaps_last
= 0;
596 /* Connect the frame-parameter names for X frames
597 to the ways of passing the parameter values to the window system.
599 The name of a parameter, as a Lisp symbol,
600 has an `x-frame-parameter' property which is an integer in Lisp
601 but can be interpreted as an `enum x_frame_parm' in C. */
605 X_PARM_FOREGROUND_COLOR
,
606 X_PARM_BACKGROUND_COLOR
,
613 X_PARM_INTERNAL_BORDER_WIDTH
,
617 X_PARM_VERT_SCROLL_BAR
,
619 X_PARM_MENU_BAR_LINES
623 struct x_frame_parm_table
626 void (*setter
)( /* struct frame *frame, Lisp_Object val, oldval */ );
629 void x_set_foreground_color ();
630 void x_set_background_color ();
631 void x_set_mouse_color ();
632 void x_set_cursor_color ();
633 void x_set_border_color ();
634 void x_set_cursor_type ();
635 void x_set_icon_type ();
637 void x_set_border_width ();
638 void x_set_internal_border_width ();
639 void x_explicitly_set_name ();
640 void x_set_autoraise ();
641 void x_set_autolower ();
642 void x_set_vertical_scroll_bars ();
643 void x_set_visibility ();
644 void x_set_menu_bar_lines ();
645 void x_set_scroll_bar_width ();
646 void x_set_unsplittable ();
648 static struct x_frame_parm_table x_frame_parms
[] =
650 "foreground-color", x_set_foreground_color
,
651 "background-color", x_set_background_color
,
652 "mouse-color", x_set_mouse_color
,
653 "cursor-color", x_set_cursor_color
,
654 "border-color", x_set_border_color
,
655 "cursor-type", x_set_cursor_type
,
656 "icon-type", x_set_icon_type
,
658 "border-width", x_set_border_width
,
659 "internal-border-width", x_set_internal_border_width
,
660 "name", x_explicitly_set_name
,
661 "auto-raise", x_set_autoraise
,
662 "auto-lower", x_set_autolower
,
663 "vertical-scroll-bars", x_set_vertical_scroll_bars
,
664 "visibility", x_set_visibility
,
665 "menu-bar-lines", x_set_menu_bar_lines
,
666 "scroll-bar-width", x_set_scroll_bar_width
,
667 "unsplittable", x_set_unsplittable
,
670 /* Attach the `x-frame-parameter' properties to
671 the Lisp symbol names of parameters relevant to X. */
673 init_x_parm_symbols ()
677 for (i
= 0; i
< sizeof (x_frame_parms
) / sizeof (x_frame_parms
[0]); i
++)
678 Fput (intern (x_frame_parms
[i
].name
), Qx_frame_parameter
,
682 /* Change the parameters of FRAME as specified by ALIST.
683 If a parameter is not specially recognized, do nothing;
684 otherwise call the `x_set_...' function for that parameter. */
687 x_set_frame_parameters (f
, alist
)
693 /* If both of these parameters are present, it's more efficient to
694 set them both at once. So we wait until we've looked at the
695 entire list before we set them. */
696 Lisp_Object width
, height
;
699 Lisp_Object left
, top
;
701 /* Same with these. */
702 Lisp_Object icon_left
, icon_top
;
704 /* Record in these vectors all the parms specified. */
708 int left_no_change
= 0, top_no_change
= 0;
709 int icon_left_no_change
= 0, icon_top_no_change
= 0;
712 for (tail
= alist
; CONSP (tail
); tail
= Fcdr (tail
))
715 parms
= (Lisp_Object
*) alloca (i
* sizeof (Lisp_Object
));
716 values
= (Lisp_Object
*) alloca (i
* sizeof (Lisp_Object
));
718 /* Extract parm names and values into those vectors. */
721 for (tail
= alist
; CONSP (tail
); tail
= Fcdr (tail
))
723 Lisp_Object elt
, prop
, val
;
726 parms
[i
] = Fcar (elt
);
727 values
[i
] = Fcdr (elt
);
731 width
= height
= top
= left
= Qunbound
;
732 icon_left
= icon_top
= Qunbound
;
734 /* Now process them in reverse of specified order. */
735 for (i
--; i
>= 0; i
--)
737 Lisp_Object prop
, val
;
742 if (EQ (prop
, Qwidth
))
744 else if (EQ (prop
, Qheight
))
746 else if (EQ (prop
, Qtop
))
748 else if (EQ (prop
, Qleft
))
750 else if (EQ (prop
, Qicon_top
))
752 else if (EQ (prop
, Qicon_left
))
756 register Lisp_Object param_index
, old_value
;
758 param_index
= Fget (prop
, Qx_frame_parameter
);
759 old_value
= get_frame_param (f
, prop
);
760 store_frame_param (f
, prop
, val
);
761 if (NATNUMP (param_index
)
762 && (XFASTINT (param_index
)
763 < sizeof (x_frame_parms
)/sizeof (x_frame_parms
[0])))
764 (*x_frame_parms
[XINT (param_index
)].setter
)(f
, val
, old_value
);
768 /* Don't die if just one of these was set. */
769 if (EQ (left
, Qunbound
))
772 if (f
->display
.x
->left_pos
< 0)
773 left
= Fcons (Qplus
, Fcons (make_number (f
->display
.x
->left_pos
), Qnil
));
775 XSETINT (left
, f
->display
.x
->left_pos
);
777 if (EQ (top
, Qunbound
))
780 if (f
->display
.x
->top_pos
< 0)
781 top
= Fcons (Qplus
, Fcons (make_number (f
->display
.x
->top_pos
), Qnil
));
783 XSETINT (top
, f
->display
.x
->top_pos
);
786 /* If one of the icon positions was not set, preserve or default it. */
787 if (EQ (icon_left
, Qunbound
) || ! INTEGERP (icon_left
))
789 icon_left_no_change
= 1;
790 icon_left
= Fcdr (Fassq (Qicon_left
, f
->param_alist
));
791 if (NILP (icon_left
))
792 XSETINT (icon_left
, 0);
794 if (EQ (icon_top
, Qunbound
) || ! INTEGERP (icon_top
))
796 icon_top_no_change
= 1;
797 icon_top
= Fcdr (Fassq (Qicon_top
, f
->param_alist
));
799 XSETINT (icon_top
, 0);
802 /* Don't die if just one of these was set. */
803 if (EQ (width
, Qunbound
))
804 XSETINT (width
, FRAME_WIDTH (f
));
805 if (EQ (height
, Qunbound
))
806 XSETINT (height
, FRAME_HEIGHT (f
));
808 /* Don't set these parameters these unless they've been explicitly
809 specified. The window might be mapped or resized while we're in
810 this function, and we don't want to override that unless the lisp
811 code has asked for it.
813 Don't set these parameters unless they actually differ from the
814 window's current parameters; the window may not actually exist
819 check_frame_size (f
, &height
, &width
);
821 XSETFRAME (frame
, f
);
823 if ((NUMBERP (width
) && XINT (width
) != FRAME_WIDTH (f
))
824 || (NUMBERP (height
) && XINT (height
) != FRAME_HEIGHT (f
)))
825 Fset_frame_size (frame
, width
, height
);
827 if ((!NILP (left
) || !NILP (top
))
828 && ! (left_no_change
&& top_no_change
)
829 && ! (NUMBERP (left
) && XINT (left
) == f
->display
.x
->left_pos
830 && NUMBERP (top
) && XINT (top
) == f
->display
.x
->top_pos
))
835 /* Record the signs. */
836 f
->display
.x
->size_hint_flags
&= ~ (XNegative
| YNegative
);
837 if (EQ (left
, Qminus
))
838 f
->display
.x
->size_hint_flags
|= XNegative
;
839 else if (INTEGERP (left
))
841 leftpos
= XINT (left
);
843 f
->display
.x
->size_hint_flags
|= XNegative
;
845 else if (CONSP (left
) && EQ (XCONS (left
)->car
, Qminus
)
846 && CONSP (XCONS (left
)->cdr
)
847 && INTEGERP (XCONS (XCONS (left
)->cdr
)->car
))
849 leftpos
= - XINT (XCONS (XCONS (left
)->cdr
)->car
);
850 f
->display
.x
->size_hint_flags
|= XNegative
;
852 else if (CONSP (left
) && EQ (XCONS (left
)->car
, Qplus
)
853 && CONSP (XCONS (left
)->cdr
)
854 && INTEGERP (XCONS (XCONS (left
)->cdr
)->car
))
856 leftpos
= XINT (XCONS (XCONS (left
)->cdr
)->car
);
859 if (EQ (top
, Qminus
))
860 f
->display
.x
->size_hint_flags
|= YNegative
;
861 else if (INTEGERP (top
))
865 f
->display
.x
->size_hint_flags
|= YNegative
;
867 else if (CONSP (top
) && EQ (XCONS (top
)->car
, Qminus
)
868 && CONSP (XCONS (top
)->cdr
)
869 && INTEGERP (XCONS (XCONS (top
)->cdr
)->car
))
871 toppos
= - XINT (XCONS (XCONS (top
)->cdr
)->car
);
872 f
->display
.x
->size_hint_flags
|= YNegative
;
874 else if (CONSP (top
) && EQ (XCONS (top
)->car
, Qplus
)
875 && CONSP (XCONS (top
)->cdr
)
876 && INTEGERP (XCONS (XCONS (top
)->cdr
)->car
))
878 toppos
= XINT (XCONS (XCONS (top
)->cdr
)->car
);
882 /* Store the numeric value of the position. */
883 f
->display
.x
->top_pos
= toppos
;
884 f
->display
.x
->left_pos
= leftpos
;
886 f
->display
.x
->win_gravity
= NorthWestGravity
;
888 /* Actually set that position, and convert to absolute. */
889 x_set_offset (f
, leftpos
, toppos
, 0);
892 if ((!NILP (icon_left
) || !NILP (icon_top
))
893 && ! (icon_left_no_change
&& icon_top_no_change
))
894 x_wm_set_icon_position (f
, XINT (icon_left
), XINT (icon_top
));
898 /* Store the screen positions of frame F into XPTR and YPTR.
899 These are the positions of the containing window manager window,
900 not Emacs's own window. */
903 x_real_positions (f
, xptr
, yptr
)
910 /* This is pretty gross, but seems to be the easiest way out of
911 the problem that arises when restarting window-managers. */
914 Window outer
= XtWindow (f
->display
.x
->widget
);
916 Window outer
= f
->display
.x
->window_desc
;
918 Window tmp_root_window
;
919 Window
*tmp_children
;
922 x_catch_errors (FRAME_X_DISPLAY (f
));
925 XQueryTree (FRAME_X_DISPLAY (f
), outer
, &tmp_root_window
,
926 &f
->display
.x
->parent_desc
,
927 &tmp_children
, &tmp_nchildren
);
928 xfree (tmp_children
);
932 /* Find the position of the outside upper-left corner of
933 the inner window, with respect to the outer window. */
934 if (f
->display
.x
->parent_desc
!= FRAME_X_DISPLAY_INFO (f
)->root_window
)
936 XTranslateCoordinates (FRAME_X_DISPLAY (f
),
938 /* From-window, to-window. */
940 XtWindow (f
->display
.x
->widget
),
942 f
->display
.x
->window_desc
,
944 f
->display
.x
->parent_desc
,
946 /* From-position, to-position. */
947 0, 0, &win_x
, &win_y
,
952 win_x
+= f
->display
.x
->border_width
;
953 win_y
+= f
->display
.x
->border_width
;
956 /* It is possible for the window returned by the XQueryNotify
957 to become invalid by the time we call XTranslateCoordinates.
958 That can happen when you restart some window managers.
959 If so, we get an error in XTranslateCoordinates.
960 Detect that and try the whole thing over. */
961 if (! x_had_errors_p (FRAME_X_DISPLAY (f
)))
965 x_uncatch_errors (FRAME_X_DISPLAY (f
));
967 *xptr
= f
->display
.x
->left_pos
- win_x
;
968 *yptr
= f
->display
.x
->top_pos
- win_y
;
971 /* Insert a description of internally-recorded parameters of frame X
972 into the parameter alist *ALISTPTR that is to be given to the user.
973 Only parameters that are specific to the X window system
974 and whose values are not correctly recorded in the frame's
975 param_alist need to be considered here. */
977 x_report_frame_params (f
, alistptr
)
979 Lisp_Object
*alistptr
;
983 store_in_alist (alistptr
, Qleft
, make_number (f
->display
.x
->left_pos
));
984 store_in_alist (alistptr
, Qtop
, make_number (f
->display
.x
->top_pos
));
985 store_in_alist (alistptr
, Qborder_width
,
986 make_number (f
->display
.x
->border_width
));
987 store_in_alist (alistptr
, Qinternal_border_width
,
988 make_number (f
->display
.x
->internal_border_width
));
989 sprintf (buf
, "%ld", (long) FRAME_X_WINDOW (f
));
990 store_in_alist (alistptr
, Qwindow_id
,
992 FRAME_SAMPLE_VISIBILITY (f
);
993 store_in_alist (alistptr
, Qvisibility
,
994 (FRAME_VISIBLE_P (f
) ? Qt
995 : FRAME_ICONIFIED_P (f
) ? Qicon
: Qnil
));
996 store_in_alist (alistptr
, Qdisplay
,
997 XCONS (FRAME_X_DISPLAY_INFO (f
)->name_list_element
)->car
);
1001 /* Decide if color named COLOR is valid for the display associated with
1002 the selected frame; if so, return the rgb values in COLOR_DEF.
1003 If ALLOC is nonzero, allocate a new colormap cell. */
1006 defined_color (f
, color
, color_def
, alloc
)
1012 register int status
;
1013 Colormap screen_colormap
;
1014 Display
*display
= FRAME_X_DISPLAY (f
);
1017 screen_colormap
= DefaultColormap (display
, XDefaultScreen (display
));
1019 status
= XParseColor (display
, screen_colormap
, color
, color_def
);
1020 if (status
&& alloc
)
1022 status
= XAllocColor (display
, screen_colormap
, color_def
);
1025 /* If we got to this point, the colormap is full, so we're
1026 going to try and get the next closest color.
1027 The algorithm used is a least-squares matching, which is
1028 what X uses for closest color matching with StaticColor visuals. */
1033 long nearest_delta
, trial_delta
;
1036 no_cells
= XDisplayCells (display
, XDefaultScreen (display
));
1037 cells
= (XColor
*) alloca (sizeof (XColor
) * no_cells
);
1039 for (x
= 0; x
< no_cells
; x
++)
1042 XQueryColors (display
, screen_colormap
, cells
, no_cells
);
1044 /* I'm assuming CSE so I'm not going to condense this. */
1045 nearest_delta
= ((((color_def
->red
>> 8) - (cells
[0].red
>> 8))
1046 * ((color_def
->red
>> 8) - (cells
[0].red
>> 8)))
1048 (((color_def
->green
>> 8) - (cells
[0].green
>> 8))
1049 * ((color_def
->green
>> 8) - (cells
[0].green
>> 8)))
1051 (((color_def
->blue
>> 8) - (cells
[0].blue
>> 8))
1052 * ((color_def
->blue
>> 8) - (cells
[0].blue
>> 8))));
1053 for (x
= 1; x
< no_cells
; x
++)
1055 trial_delta
= ((((color_def
->red
>> 8) - (cells
[x
].red
>> 8))
1056 * ((color_def
->red
>> 8) - (cells
[x
].red
>> 8)))
1058 (((color_def
->green
>> 8) - (cells
[x
].green
>> 8))
1059 * ((color_def
->green
>> 8) - (cells
[x
].green
>> 8)))
1061 (((color_def
->blue
>> 8) - (cells
[x
].blue
>> 8))
1062 * ((color_def
->blue
>> 8) - (cells
[x
].blue
>> 8))));
1063 if (trial_delta
< nearest_delta
)
1066 nearest_delta
= trial_delta
;
1069 color_def
->red
= cells
[nearest
].red
;
1070 color_def
->green
= cells
[nearest
].green
;
1071 color_def
->blue
= cells
[nearest
].blue
;
1072 status
= XAllocColor (display
, screen_colormap
, color_def
);
1083 /* Given a string ARG naming a color, compute a pixel value from it
1084 suitable for screen F.
1085 If F is not a color screen, return DEF (default) regardless of what
1089 x_decode_color (f
, arg
, def
)
1096 CHECK_STRING (arg
, 0);
1098 if (strcmp (XSTRING (arg
)->data
, "black") == 0)
1099 return BLACK_PIX_DEFAULT (f
);
1100 else if (strcmp (XSTRING (arg
)->data
, "white") == 0)
1101 return WHITE_PIX_DEFAULT (f
);
1103 if (FRAME_X_DISPLAY_INFO (f
)->n_planes
== 1)
1106 /* defined_color is responsible for coping with failures
1107 by looking for a near-miss. */
1108 if (defined_color (f
, XSTRING (arg
)->data
, &cdef
, 1))
1111 /* defined_color failed; return an ultimate default. */
1115 /* Functions called only from `x_set_frame_param'
1116 to set individual parameters.
1118 If FRAME_X_WINDOW (f) is 0,
1119 the frame is being created and its X-window does not exist yet.
1120 In that case, just record the parameter's new value
1121 in the standard place; do not attempt to change the window. */
1124 x_set_foreground_color (f
, arg
, oldval
)
1126 Lisp_Object arg
, oldval
;
1128 f
->display
.x
->foreground_pixel
1129 = x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1130 if (FRAME_X_WINDOW (f
) != 0)
1133 XSetForeground (FRAME_X_DISPLAY (f
), f
->display
.x
->normal_gc
,
1134 f
->display
.x
->foreground_pixel
);
1135 XSetBackground (FRAME_X_DISPLAY (f
), f
->display
.x
->reverse_gc
,
1136 f
->display
.x
->foreground_pixel
);
1138 recompute_basic_faces (f
);
1139 if (FRAME_VISIBLE_P (f
))
1145 x_set_background_color (f
, arg
, oldval
)
1147 Lisp_Object arg
, oldval
;
1152 f
->display
.x
->background_pixel
1153 = x_decode_color (f
, arg
, WHITE_PIX_DEFAULT (f
));
1155 if (FRAME_X_WINDOW (f
) != 0)
1158 /* The main frame area. */
1159 XSetBackground (FRAME_X_DISPLAY (f
), f
->display
.x
->normal_gc
,
1160 f
->display
.x
->background_pixel
);
1161 XSetForeground (FRAME_X_DISPLAY (f
), f
->display
.x
->reverse_gc
,
1162 f
->display
.x
->background_pixel
);
1163 XSetForeground (FRAME_X_DISPLAY (f
), f
->display
.x
->cursor_gc
,
1164 f
->display
.x
->background_pixel
);
1165 XSetWindowBackground (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1166 f
->display
.x
->background_pixel
);
1169 for (bar
= FRAME_SCROLL_BARS (f
); !NILP (bar
);
1170 bar
= XSCROLL_BAR (bar
)->next
)
1171 XSetWindowBackground (FRAME_X_DISPLAY (f
),
1172 SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar
)),
1173 f
->display
.x
->background_pixel
);
1177 recompute_basic_faces (f
);
1179 if (FRAME_VISIBLE_P (f
))
1185 x_set_mouse_color (f
, arg
, oldval
)
1187 Lisp_Object arg
, oldval
;
1189 Cursor cursor
, nontext_cursor
, mode_cursor
, cross_cursor
;
1192 if (!EQ (Qnil
, arg
))
1193 f
->display
.x
->mouse_pixel
1194 = x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1195 mask_color
= f
->display
.x
->background_pixel
;
1196 /* No invisible pointers. */
1197 if (mask_color
== f
->display
.x
->mouse_pixel
1198 && mask_color
== f
->display
.x
->background_pixel
)
1199 f
->display
.x
->mouse_pixel
= f
->display
.x
->foreground_pixel
;
1203 /* It's not okay to crash if the user selects a screwy cursor. */
1204 x_catch_errors (FRAME_X_DISPLAY (f
));
1206 if (!EQ (Qnil
, Vx_pointer_shape
))
1208 CHECK_NUMBER (Vx_pointer_shape
, 0);
1209 cursor
= XCreateFontCursor (FRAME_X_DISPLAY (f
), XINT (Vx_pointer_shape
));
1212 cursor
= XCreateFontCursor (FRAME_X_DISPLAY (f
), XC_xterm
);
1213 x_check_errors (FRAME_X_DISPLAY (f
), "bad text pointer cursor: %s");
1215 if (!EQ (Qnil
, Vx_nontext_pointer_shape
))
1217 CHECK_NUMBER (Vx_nontext_pointer_shape
, 0);
1218 nontext_cursor
= XCreateFontCursor (FRAME_X_DISPLAY (f
),
1219 XINT (Vx_nontext_pointer_shape
));
1222 nontext_cursor
= XCreateFontCursor (FRAME_X_DISPLAY (f
), XC_left_ptr
);
1223 x_check_errors (FRAME_X_DISPLAY (f
), "bad nontext pointer cursor: %s");
1225 if (!EQ (Qnil
, Vx_mode_pointer_shape
))
1227 CHECK_NUMBER (Vx_mode_pointer_shape
, 0);
1228 mode_cursor
= XCreateFontCursor (FRAME_X_DISPLAY (f
),
1229 XINT (Vx_mode_pointer_shape
));
1232 mode_cursor
= XCreateFontCursor (FRAME_X_DISPLAY (f
), XC_xterm
);
1233 x_check_errors (FRAME_X_DISPLAY (f
), "bad modeline pointer cursor: %s");
1235 if (!EQ (Qnil
, Vx_sensitive_text_pointer_shape
))
1237 CHECK_NUMBER (Vx_sensitive_text_pointer_shape
, 0);
1239 = XCreateFontCursor (FRAME_X_DISPLAY (f
),
1240 XINT (Vx_sensitive_text_pointer_shape
));
1243 cross_cursor
= XCreateFontCursor (FRAME_X_DISPLAY (f
), XC_crosshair
);
1245 /* Check and report errors with the above calls. */
1246 x_check_errors (FRAME_X_DISPLAY (f
), "can't set cursor shape: %s");
1247 x_uncatch_errors (FRAME_X_DISPLAY (f
));
1250 XColor fore_color
, back_color
;
1252 fore_color
.pixel
= f
->display
.x
->mouse_pixel
;
1253 back_color
.pixel
= mask_color
;
1254 XQueryColor (FRAME_X_DISPLAY (f
),
1255 DefaultColormap (FRAME_X_DISPLAY (f
),
1256 DefaultScreen (FRAME_X_DISPLAY (f
))),
1258 XQueryColor (FRAME_X_DISPLAY (f
),
1259 DefaultColormap (FRAME_X_DISPLAY (f
),
1260 DefaultScreen (FRAME_X_DISPLAY (f
))),
1262 XRecolorCursor (FRAME_X_DISPLAY (f
), cursor
,
1263 &fore_color
, &back_color
);
1264 XRecolorCursor (FRAME_X_DISPLAY (f
), nontext_cursor
,
1265 &fore_color
, &back_color
);
1266 XRecolorCursor (FRAME_X_DISPLAY (f
), mode_cursor
,
1267 &fore_color
, &back_color
);
1268 XRecolorCursor (FRAME_X_DISPLAY (f
), cross_cursor
,
1269 &fore_color
, &back_color
);
1272 if (FRAME_X_WINDOW (f
) != 0)
1274 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), cursor
);
1277 if (cursor
!= f
->display
.x
->text_cursor
&& f
->display
.x
->text_cursor
!= 0)
1278 XFreeCursor (FRAME_X_DISPLAY (f
), f
->display
.x
->text_cursor
);
1279 f
->display
.x
->text_cursor
= cursor
;
1281 if (nontext_cursor
!= f
->display
.x
->nontext_cursor
1282 && f
->display
.x
->nontext_cursor
!= 0)
1283 XFreeCursor (FRAME_X_DISPLAY (f
), f
->display
.x
->nontext_cursor
);
1284 f
->display
.x
->nontext_cursor
= nontext_cursor
;
1286 if (mode_cursor
!= f
->display
.x
->modeline_cursor
1287 && f
->display
.x
->modeline_cursor
!= 0)
1288 XFreeCursor (FRAME_X_DISPLAY (f
), f
->display
.x
->modeline_cursor
);
1289 f
->display
.x
->modeline_cursor
= mode_cursor
;
1290 if (cross_cursor
!= f
->display
.x
->cross_cursor
1291 && f
->display
.x
->cross_cursor
!= 0)
1292 XFreeCursor (FRAME_X_DISPLAY (f
), f
->display
.x
->cross_cursor
);
1293 f
->display
.x
->cross_cursor
= cross_cursor
;
1295 XFlush (FRAME_X_DISPLAY (f
));
1300 x_set_cursor_color (f
, arg
, oldval
)
1302 Lisp_Object arg
, oldval
;
1304 unsigned long fore_pixel
;
1306 if (!EQ (Vx_cursor_fore_pixel
, Qnil
))
1307 fore_pixel
= x_decode_color (f
, Vx_cursor_fore_pixel
,
1308 WHITE_PIX_DEFAULT (f
));
1310 fore_pixel
= f
->display
.x
->background_pixel
;
1311 f
->display
.x
->cursor_pixel
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1313 /* Make sure that the cursor color differs from the background color. */
1314 if (f
->display
.x
->cursor_pixel
== f
->display
.x
->background_pixel
)
1316 f
->display
.x
->cursor_pixel
= f
->display
.x
->mouse_pixel
;
1317 if (f
->display
.x
->cursor_pixel
== fore_pixel
)
1318 fore_pixel
= f
->display
.x
->background_pixel
;
1320 f
->display
.x
->cursor_foreground_pixel
= fore_pixel
;
1322 if (FRAME_X_WINDOW (f
) != 0)
1325 XSetBackground (FRAME_X_DISPLAY (f
), f
->display
.x
->cursor_gc
,
1326 f
->display
.x
->cursor_pixel
);
1327 XSetForeground (FRAME_X_DISPLAY (f
), f
->display
.x
->cursor_gc
,
1331 if (FRAME_VISIBLE_P (f
))
1333 x_display_cursor (f
, 0);
1334 x_display_cursor (f
, 1);
1339 /* Set the border-color of frame F to value described by ARG.
1340 ARG can be a string naming a color.
1341 The border-color is used for the border that is drawn by the X server.
1342 Note that this does not fully take effect if done before
1343 F has an x-window; it must be redone when the window is created.
1345 Note: this is done in two routines because of the way X10 works.
1347 Note: under X11, this is normally the province of the window manager,
1348 and so emacs' border colors may be overridden. */
1351 x_set_border_color (f
, arg
, oldval
)
1353 Lisp_Object arg
, oldval
;
1358 CHECK_STRING (arg
, 0);
1359 str
= XSTRING (arg
)->data
;
1361 pix
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1363 x_set_border_pixel (f
, pix
);
1366 /* Set the border-color of frame F to pixel value PIX.
1367 Note that this does not fully take effect if done before
1368 F has an x-window. */
1370 x_set_border_pixel (f
, pix
)
1374 f
->display
.x
->border_pixel
= pix
;
1376 if (FRAME_X_WINDOW (f
) != 0 && f
->display
.x
->border_width
> 0)
1382 XSetWindowBorder (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1383 (unsigned long)pix
);
1386 if (FRAME_VISIBLE_P (f
))
1392 x_set_cursor_type (f
, arg
, oldval
)
1394 Lisp_Object arg
, oldval
;
1398 FRAME_DESIRED_CURSOR (f
) = bar_cursor
;
1399 f
->display
.x
->cursor_width
= 2;
1401 else if (CONSP (arg
) && EQ (XCONS (arg
)->car
, Qbar
)
1402 && INTEGERP (XCONS (arg
)->cdr
))
1404 FRAME_DESIRED_CURSOR (f
) = bar_cursor
;
1405 f
->display
.x
->cursor_width
= XINT (XCONS (arg
)->cdr
);
1408 /* Treat anything unknown as "box cursor".
1409 It was bad to signal an error; people have trouble fixing
1410 .Xdefaults with Emacs, when it has something bad in it. */
1411 FRAME_DESIRED_CURSOR (f
) = filled_box_cursor
;
1413 /* Make sure the cursor gets redrawn. This is overkill, but how
1414 often do people change cursor types? */
1415 update_mode_lines
++;
1419 x_set_icon_type (f
, arg
, oldval
)
1421 Lisp_Object arg
, oldval
;
1428 if (STRINGP (oldval
) && EQ (Fstring_equal (oldval
, arg
), Qt
))
1431 else if (!STRINGP (oldval
) && EQ (oldval
, Qnil
) == EQ (arg
, Qnil
))
1436 result
= x_text_icon (f
, 0);
1438 result
= x_bitmap_icon (f
, arg
);
1443 error ("No icon window available");
1446 /* If the window was unmapped (and its icon was mapped),
1447 the new icon is not mapped, so map the window in its stead. */
1448 if (FRAME_VISIBLE_P (f
))
1450 #ifdef USE_X_TOOLKIT
1451 XtPopup (f
->display
.x
->widget
, XtGrabNone
);
1453 XMapWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
1456 XFlush (FRAME_X_DISPLAY (f
));
1460 /* Return non-nil if frame F wants a bitmap icon. */
1468 tem
= assq_no_quit (Qicon_type
, f
->param_alist
);
1470 return XCONS (tem
)->cdr
;
1475 extern Lisp_Object
x_new_font ();
1478 x_set_font (f
, arg
, oldval
)
1480 Lisp_Object arg
, oldval
;
1484 CHECK_STRING (arg
, 1);
1487 result
= x_new_font (f
, XSTRING (arg
)->data
);
1490 if (EQ (result
, Qnil
))
1491 error ("Font \"%s\" is not defined", XSTRING (arg
)->data
);
1492 else if (EQ (result
, Qt
))
1493 error ("the characters of the given font have varying widths");
1494 else if (STRINGP (result
))
1496 recompute_basic_faces (f
);
1497 store_frame_param (f
, Qfont
, result
);
1504 x_set_border_width (f
, arg
, oldval
)
1506 Lisp_Object arg
, oldval
;
1508 CHECK_NUMBER (arg
, 0);
1510 if (XINT (arg
) == f
->display
.x
->border_width
)
1513 if (FRAME_X_WINDOW (f
) != 0)
1514 error ("Cannot change the border width of a window");
1516 f
->display
.x
->border_width
= XINT (arg
);
1520 x_set_internal_border_width (f
, arg
, oldval
)
1522 Lisp_Object arg
, oldval
;
1525 int old
= f
->display
.x
->internal_border_width
;
1527 CHECK_NUMBER (arg
, 0);
1528 f
->display
.x
->internal_border_width
= XINT (arg
);
1529 if (f
->display
.x
->internal_border_width
< 0)
1530 f
->display
.x
->internal_border_width
= 0;
1532 if (f
->display
.x
->internal_border_width
== old
)
1535 if (FRAME_X_WINDOW (f
) != 0)
1538 x_set_window_size (f
, 0, f
->width
, f
->height
);
1540 x_set_resize_hint (f
);
1542 XFlush (FRAME_X_DISPLAY (f
));
1544 SET_FRAME_GARBAGED (f
);
1549 x_set_visibility (f
, value
, oldval
)
1551 Lisp_Object value
, oldval
;
1554 XSETFRAME (frame
, f
);
1557 Fmake_frame_invisible (frame
, Qt
);
1558 else if (EQ (value
, Qicon
))
1559 Ficonify_frame (frame
);
1561 Fmake_frame_visible (frame
);
1565 x_set_menu_bar_lines_1 (window
, n
)
1569 struct window
*w
= XWINDOW (window
);
1571 XSETFASTINT (w
->top
, XFASTINT (w
->top
) + n
);
1572 XSETFASTINT (w
->height
, XFASTINT (w
->height
) - n
);
1574 /* Handle just the top child in a vertical split. */
1575 if (!NILP (w
->vchild
))
1576 x_set_menu_bar_lines_1 (w
->vchild
, n
);
1578 /* Adjust all children in a horizontal split. */
1579 for (window
= w
->hchild
; !NILP (window
); window
= w
->next
)
1581 w
= XWINDOW (window
);
1582 x_set_menu_bar_lines_1 (window
, n
);
1587 x_set_menu_bar_lines (f
, value
, oldval
)
1589 Lisp_Object value
, oldval
;
1592 int olines
= FRAME_MENU_BAR_LINES (f
);
1594 /* Right now, menu bars don't work properly in minibuf-only frames;
1595 most of the commands try to apply themselves to the minibuffer
1596 frame itslef, and get an error because you can't switch buffers
1597 in or split the minibuffer window. */
1598 if (FRAME_MINIBUF_ONLY_P (f
))
1601 if (INTEGERP (value
))
1602 nlines
= XINT (value
);
1606 #ifdef USE_X_TOOLKIT
1607 FRAME_MENU_BAR_LINES (f
) = 0;
1609 FRAME_EXTERNAL_MENU_BAR (f
) = 1;
1612 if (FRAME_EXTERNAL_MENU_BAR (f
) == 1)
1613 free_frame_menubar (f
);
1614 FRAME_EXTERNAL_MENU_BAR (f
) = 0;
1615 f
->display
.x
->menubar_widget
= 0;
1617 #else /* not USE_X_TOOLKIT */
1618 FRAME_MENU_BAR_LINES (f
) = nlines
;
1619 x_set_menu_bar_lines_1 (f
->root_window
, nlines
- olines
);
1620 #endif /* not USE_X_TOOLKIT */
1623 /* Change the name of frame F to NAME. If NAME is nil, set F's name to
1626 If EXPLICIT is non-zero, that indicates that lisp code is setting the
1627 name; if NAME is a string, set F's name to NAME and set
1628 F->explicit_name; if NAME is Qnil, then clear F->explicit_name.
1630 If EXPLICIT is zero, that indicates that Emacs redisplay code is
1631 suggesting a new name, which lisp code should override; if
1632 F->explicit_name is set, ignore the new name; otherwise, set it. */
1635 x_set_name (f
, name
, explicit)
1640 /* Make sure that requests from lisp code override requests from
1641 Emacs redisplay code. */
1644 /* If we're switching from explicit to implicit, we had better
1645 update the mode lines and thereby update the title. */
1646 if (f
->explicit_name
&& NILP (name
))
1647 update_mode_lines
= 1;
1649 f
->explicit_name
= ! NILP (name
);
1651 else if (f
->explicit_name
)
1654 /* If NAME is nil, set the name to the x_id_name. */
1657 /* Check for no change needed in this very common case
1658 before we do any consing. */
1659 if (!strcmp (FRAME_X_DISPLAY_INFO (f
)->x_id_name
,
1660 XSTRING (f
->name
)->data
))
1662 name
= build_string (FRAME_X_DISPLAY_INFO (f
)->x_id_name
);
1665 CHECK_STRING (name
, 0);
1667 /* Don't change the name if it's already NAME. */
1668 if (! NILP (Fstring_equal (name
, f
->name
)))
1671 if (FRAME_X_WINDOW (f
))
1677 text
.value
= XSTRING (name
)->data
;
1678 text
.encoding
= XA_STRING
;
1680 text
.nitems
= XSTRING (name
)->size
;
1681 #ifdef USE_X_TOOLKIT
1682 XSetWMName (FRAME_X_DISPLAY (f
),
1683 XtWindow (f
->display
.x
->widget
), &text
);
1684 XSetWMIconName (FRAME_X_DISPLAY (f
), XtWindow (f
->display
.x
->widget
),
1686 #else /* not USE_X_TOOLKIT */
1687 XSetWMName (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), &text
);
1688 XSetWMIconName (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), &text
);
1689 #endif /* not USE_X_TOOLKIT */
1691 #else /* not HAVE_X11R4 */
1692 XSetIconName (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1693 XSTRING (name
)->data
);
1694 XStoreName (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1695 XSTRING (name
)->data
);
1696 #endif /* not HAVE_X11R4 */
1703 /* This function should be called when the user's lisp code has
1704 specified a name for the frame; the name will override any set by the
1707 x_explicitly_set_name (f
, arg
, oldval
)
1709 Lisp_Object arg
, oldval
;
1711 x_set_name (f
, arg
, 1);
1714 /* This function should be called by Emacs redisplay code to set the
1715 name; names set this way will never override names set by the user's
1718 x_implicitly_set_name (f
, arg
, oldval
)
1720 Lisp_Object arg
, oldval
;
1722 x_set_name (f
, arg
, 0);
1726 x_set_autoraise (f
, arg
, oldval
)
1728 Lisp_Object arg
, oldval
;
1730 f
->auto_raise
= !EQ (Qnil
, arg
);
1734 x_set_autolower (f
, arg
, oldval
)
1736 Lisp_Object arg
, oldval
;
1738 f
->auto_lower
= !EQ (Qnil
, arg
);
1742 x_set_unsplittable (f
, arg
, oldval
)
1744 Lisp_Object arg
, oldval
;
1746 f
->no_split
= !NILP (arg
);
1750 x_set_vertical_scroll_bars (f
, arg
, oldval
)
1752 Lisp_Object arg
, oldval
;
1754 if (NILP (arg
) != ! FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
1756 FRAME_HAS_VERTICAL_SCROLL_BARS (f
) = ! NILP (arg
);
1758 /* We set this parameter before creating the X window for the
1759 frame, so we can get the geometry right from the start.
1760 However, if the window hasn't been created yet, we shouldn't
1761 call x_set_window_size. */
1762 if (FRAME_X_WINDOW (f
))
1763 x_set_window_size (f
, 0, FRAME_WIDTH (f
), FRAME_HEIGHT (f
));
1768 x_set_scroll_bar_width (f
, arg
, oldval
)
1770 Lisp_Object arg
, oldval
;
1774 FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) = 0;
1775 FRAME_SCROLL_BAR_COLS (f
) = 2;
1777 else if (INTEGERP (arg
) && XINT (arg
) > 0
1778 && XFASTINT (arg
) != FRAME_SCROLL_BAR_PIXEL_WIDTH (f
))
1780 int wid
= FONT_WIDTH (f
->display
.x
->font
);
1781 FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) = XFASTINT (arg
);
1782 FRAME_SCROLL_BAR_COLS (f
) = (XFASTINT (arg
) + wid
-1) / wid
;
1783 if (FRAME_X_WINDOW (f
))
1784 x_set_window_size (f
, 0, FRAME_WIDTH (f
), FRAME_HEIGHT (f
));
1788 /* Subroutines of creating an X frame. */
1790 /* Make sure that Vx_resource_name is set to a reasonable value. */
1792 validate_x_resource_name ()
1795 /* Number of valid characters in the resource name. */
1797 /* Number of invalid characters in the resource name. */
1802 if (STRINGP (Vx_resource_name
))
1804 unsigned char *p
= XSTRING (Vx_resource_name
)->data
;
1807 len
= XSTRING (Vx_resource_name
)->size
;
1809 /* Only letters, digits, - and _ are valid in resource names.
1810 Count the valid characters and count the invalid ones. */
1811 for (i
= 0; i
< len
; i
++)
1814 if (! ((c
>= 'a' && c
<= 'z')
1815 || (c
>= 'A' && c
<= 'Z')
1816 || (c
>= '0' && c
<= '9')
1817 || c
== '-' || c
== '_'))
1824 /* Not a string => completely invalid. */
1825 bad_count
= 5, good_count
= 0;
1827 /* If name is valid already, return. */
1831 /* If name is entirely invalid, or nearly so, use `emacs'. */
1833 || (good_count
== 1 && bad_count
> 0))
1835 Vx_resource_name
= make_string ("emacs", 5);
1839 /* Name is partly valid. Copy it and replace the invalid characters
1840 with underscores. */
1842 Vx_resource_name
= new = Fcopy_sequence (Vx_resource_name
);
1844 for (i
= 0; i
< len
; i
++)
1846 int c
= XSTRING (new)->data
[i
];
1847 if (! ((c
>= 'a' && c
<= 'z')
1848 || (c
>= 'A' && c
<= 'Z')
1849 || (c
>= '0' && c
<= '9')
1850 || c
== '-' || c
== '_'))
1851 XSTRING (new)->data
[i
] = '_';
1856 extern char *x_get_string_resource ();
1858 DEFUN ("x-get-resource", Fx_get_resource
, Sx_get_resource
, 2, 4, 0,
1859 "Return the value of ATTRIBUTE, of class CLASS, from the X defaults database.\n\
1860 This uses `INSTANCE.ATTRIBUTE' as the key and `Emacs.CLASS' as the\n\
1861 class, where INSTANCE is the name under which Emacs was invoked, or\n\
1862 the name specified by the `-name' or `-rn' command-line arguments.\n\
1864 The optional arguments COMPONENT and SUBCLASS add to the key and the\n\
1865 class, respectively. You must specify both of them or neither.\n\
1866 If you specify them, the key is `INSTANCE.COMPONENT.ATTRIBUTE'\n\
1867 and the class is `Emacs.CLASS.SUBCLASS'.")
1868 (attribute
, class, component
, subclass
)
1869 Lisp_Object attribute
, class, component
, subclass
;
1871 register char *value
;
1874 Lisp_Object resname
;
1878 CHECK_STRING (attribute
, 0);
1879 CHECK_STRING (class, 0);
1881 if (!NILP (component
))
1882 CHECK_STRING (component
, 1);
1883 if (!NILP (subclass
))
1884 CHECK_STRING (subclass
, 2);
1885 if (NILP (component
) != NILP (subclass
))
1886 error ("x-get-resource: must specify both COMPONENT and SUBCLASS or neither");
1888 validate_x_resource_name ();
1889 resname
= Vx_resource_name
;
1891 if (NILP (component
))
1893 /* Allocate space for the components, the dots which separate them,
1894 and the final '\0'. */
1895 name_key
= (char *) alloca (XSTRING (resname
)->size
1896 + XSTRING (attribute
)->size
1898 class_key
= (char *) alloca ((sizeof (EMACS_CLASS
) - 1)
1899 + XSTRING (class)->size
1902 sprintf (name_key
, "%s.%s",
1903 XSTRING (resname
)->data
,
1904 XSTRING (attribute
)->data
);
1905 sprintf (class_key
, "%s.%s",
1907 XSTRING (class)->data
);
1911 name_key
= (char *) alloca (XSTRING (resname
)->size
1912 + XSTRING (component
)->size
1913 + XSTRING (attribute
)->size
1916 class_key
= (char *) alloca ((sizeof (EMACS_CLASS
) - 1)
1917 + XSTRING (class)->size
1918 + XSTRING (subclass
)->size
1921 sprintf (name_key
, "%s.%s.%s",
1922 XSTRING (resname
)->data
,
1923 XSTRING (component
)->data
,
1924 XSTRING (attribute
)->data
);
1925 sprintf (class_key
, "%s.%s.%s",
1927 XSTRING (class)->data
,
1928 XSTRING (subclass
)->data
);
1931 value
= x_get_string_resource (check_x_display_info (Qnil
)->xrdb
,
1932 name_key
, class_key
);
1934 if (value
!= (char *) 0)
1935 return build_string (value
);
1940 /* Used when C code wants a resource value. */
1943 x_get_resource_string (attribute
, class)
1944 char *attribute
, *class;
1946 register char *value
;
1950 /* Allocate space for the components, the dots which separate them,
1951 and the final '\0'. */
1952 name_key
= (char *) alloca (XSTRING (Vinvocation_name
)->size
1953 + strlen (attribute
) + 2);
1954 class_key
= (char *) alloca ((sizeof (EMACS_CLASS
) - 1)
1955 + strlen (class) + 2);
1957 sprintf (name_key
, "%s.%s",
1958 XSTRING (Vinvocation_name
)->data
,
1960 sprintf (class_key
, "%s.%s", EMACS_CLASS
, class);
1962 return x_get_string_resource (FRAME_X_DISPLAY_INFO (selected_frame
)->xrdb
,
1963 name_key
, class_key
);
1966 /* Types we might convert a resource string into. */
1969 number
, boolean
, string
, symbol
1972 /* Return the value of parameter PARAM.
1974 First search ALIST, then Vdefault_frame_alist, then the X defaults
1975 database, using ATTRIBUTE as the attribute name and CLASS as its class.
1977 Convert the resource to the type specified by desired_type.
1979 If no default is specified, return Qunbound. If you call
1980 x_get_arg, make sure you deal with Qunbound in a reasonable way,
1981 and don't let it get stored in any Lisp-visible variables! */
1984 x_get_arg (alist
, param
, attribute
, class, type
)
1985 Lisp_Object alist
, param
;
1988 enum resource_types type
;
1990 register Lisp_Object tem
;
1992 tem
= Fassq (param
, alist
);
1994 tem
= Fassq (param
, Vdefault_frame_alist
);
2000 tem
= Fx_get_resource (build_string (attribute
),
2001 build_string (class),
2010 return make_number (atoi (XSTRING (tem
)->data
));
2013 tem
= Fdowncase (tem
);
2014 if (!strcmp (XSTRING (tem
)->data
, "on")
2015 || !strcmp (XSTRING (tem
)->data
, "true"))
2024 /* As a special case, we map the values `true' and `on'
2025 to Qt, and `false' and `off' to Qnil. */
2028 lower
= Fdowncase (tem
);
2029 if (!strcmp (XSTRING (lower
)->data
, "on")
2030 || !strcmp (XSTRING (lower
)->data
, "true"))
2032 else if (!strcmp (XSTRING (lower
)->data
, "off")
2033 || !strcmp (XSTRING (lower
)->data
, "false"))
2036 return Fintern (tem
, Qnil
);
2049 /* Record in frame F the specified or default value according to ALIST
2050 of the parameter named PARAM (a Lisp symbol).
2051 If no value is specified for PARAM, look for an X default for XPROP
2052 on the frame named NAME.
2053 If that is not found either, use the value DEFLT. */
2056 x_default_parameter (f
, alist
, prop
, deflt
, xprop
, xclass
, type
)
2063 enum resource_types type
;
2067 tem
= x_get_arg (alist
, prop
, xprop
, xclass
, type
);
2068 if (EQ (tem
, Qunbound
))
2070 x_set_frame_parameters (f
, Fcons (Fcons (prop
, tem
), Qnil
));
2074 DEFUN ("x-parse-geometry", Fx_parse_geometry
, Sx_parse_geometry
, 1, 1, 0,
2075 "Parse an X-style geometry string STRING.\n\
2076 Returns an alist of the form ((top . TOP), (left . LEFT) ... ).\n\
2077 The properties returned may include `top', `left', `height', and `width'.\n\
2078 The value of `left' or `top' may be an integer,\n\
2079 or a list (+ N) meaning N pixels relative to top/left corner,\n\
2080 or a list (- N) meaning -N pixels relative to bottom/right corner.")
2085 unsigned int width
, height
;
2088 CHECK_STRING (string
, 0);
2090 geometry
= XParseGeometry ((char *) XSTRING (string
)->data
,
2091 &x
, &y
, &width
, &height
);
2094 if (!!(geometry
& XValue
) != !!(geometry
& YValue
))
2095 error ("Must specify both x and y position, or neither");
2099 if (geometry
& XValue
)
2101 Lisp_Object element
;
2103 if (x
>= 0 && (geometry
& XNegative
))
2104 element
= Fcons (Qleft
, Fcons (Qminus
, Fcons (make_number (-x
), Qnil
)));
2105 else if (x
< 0 && ! (geometry
& XNegative
))
2106 element
= Fcons (Qleft
, Fcons (Qplus
, Fcons (make_number (x
), Qnil
)));
2108 element
= Fcons (Qleft
, make_number (x
));
2109 result
= Fcons (element
, result
);
2112 if (geometry
& YValue
)
2114 Lisp_Object element
;
2116 if (y
>= 0 && (geometry
& YNegative
))
2117 element
= Fcons (Qtop
, Fcons (Qminus
, Fcons (make_number (-y
), Qnil
)));
2118 else if (y
< 0 && ! (geometry
& YNegative
))
2119 element
= Fcons (Qtop
, Fcons (Qplus
, Fcons (make_number (y
), Qnil
)));
2121 element
= Fcons (Qtop
, make_number (y
));
2122 result
= Fcons (element
, result
);
2125 if (geometry
& WidthValue
)
2126 result
= Fcons (Fcons (Qwidth
, make_number (width
)), result
);
2127 if (geometry
& HeightValue
)
2128 result
= Fcons (Fcons (Qheight
, make_number (height
)), result
);
2133 /* Calculate the desired size and position of this window,
2134 and return the flags saying which aspects were specified.
2136 This function does not make the coordinates positive. */
2138 #define DEFAULT_ROWS 40
2139 #define DEFAULT_COLS 80
2142 x_figure_window_size (f
, parms
)
2146 register Lisp_Object tem0
, tem1
, tem2
;
2147 int height
, width
, left
, top
;
2148 register int geometry
;
2149 long window_prompting
= 0;
2151 /* Default values if we fall through.
2152 Actually, if that happens we should get
2153 window manager prompting. */
2154 f
->width
= DEFAULT_COLS
;
2155 f
->height
= DEFAULT_ROWS
;
2156 /* Window managers expect that if program-specified
2157 positions are not (0,0), they're intentional, not defaults. */
2158 f
->display
.x
->top_pos
= 0;
2159 f
->display
.x
->left_pos
= 0;
2161 tem0
= x_get_arg (parms
, Qheight
, 0, 0, number
);
2162 tem1
= x_get_arg (parms
, Qwidth
, 0, 0, number
);
2163 tem2
= x_get_arg (parms
, Quser_size
, 0, 0, number
);
2164 if (! EQ (tem0
, Qunbound
) || ! EQ (tem1
, Qunbound
))
2166 if (!EQ (tem0
, Qunbound
))
2168 CHECK_NUMBER (tem0
, 0);
2169 f
->height
= XINT (tem0
);
2171 if (!EQ (tem1
, Qunbound
))
2173 CHECK_NUMBER (tem1
, 0);
2174 f
->width
= XINT (tem1
);
2176 if (!NILP (tem2
) && !EQ (tem2
, Qunbound
))
2177 window_prompting
|= USSize
;
2179 window_prompting
|= PSize
;
2182 f
->display
.x
->vertical_scroll_bar_extra
2183 = (!FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
2185 : FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) > 0
2186 ? FRAME_SCROLL_BAR_PIXEL_WIDTH (f
)
2187 : (FRAME_SCROLL_BAR_COLS (f
) * FONT_WIDTH (f
->display
.x
->font
)));
2188 f
->display
.x
->pixel_width
= CHAR_TO_PIXEL_WIDTH (f
, f
->width
);
2189 f
->display
.x
->pixel_height
= CHAR_TO_PIXEL_HEIGHT (f
, f
->height
);
2191 tem0
= x_get_arg (parms
, Qtop
, 0, 0, number
);
2192 tem1
= x_get_arg (parms
, Qleft
, 0, 0, number
);
2193 tem2
= x_get_arg (parms
, Quser_position
, 0, 0, number
);
2194 if (! EQ (tem0
, Qunbound
) || ! EQ (tem1
, Qunbound
))
2196 if (EQ (tem0
, Qminus
))
2198 f
->display
.x
->top_pos
= 0;
2199 window_prompting
|= YNegative
;
2201 else if (CONSP (tem0
) && EQ (XCONS (tem0
)->car
, Qminus
)
2202 && CONSP (XCONS (tem0
)->cdr
)
2203 && INTEGERP (XCONS (XCONS (tem0
)->cdr
)->car
))
2205 f
->display
.x
->top_pos
= - XINT (XCONS (XCONS (tem0
)->cdr
)->car
);
2206 window_prompting
|= YNegative
;
2208 else if (CONSP (tem0
) && EQ (XCONS (tem0
)->car
, Qplus
)
2209 && CONSP (XCONS (tem0
)->cdr
)
2210 && INTEGERP (XCONS (XCONS (tem0
)->cdr
)->car
))
2212 f
->display
.x
->top_pos
= XINT (XCONS (XCONS (tem0
)->cdr
)->car
);
2214 else if (EQ (tem0
, Qunbound
))
2215 f
->display
.x
->top_pos
= 0;
2218 CHECK_NUMBER (tem0
, 0);
2219 f
->display
.x
->top_pos
= XINT (tem0
);
2220 if (f
->display
.x
->top_pos
< 0)
2221 window_prompting
|= YNegative
;
2224 if (EQ (tem1
, Qminus
))
2226 f
->display
.x
->left_pos
= 0;
2227 window_prompting
|= XNegative
;
2229 else if (CONSP (tem1
) && EQ (XCONS (tem1
)->car
, Qminus
)
2230 && CONSP (XCONS (tem1
)->cdr
)
2231 && INTEGERP (XCONS (XCONS (tem1
)->cdr
)->car
))
2233 f
->display
.x
->left_pos
= - XINT (XCONS (XCONS (tem1
)->cdr
)->car
);
2234 window_prompting
|= XNegative
;
2236 else if (CONSP (tem1
) && EQ (XCONS (tem1
)->car
, Qplus
)
2237 && CONSP (XCONS (tem1
)->cdr
)
2238 && INTEGERP (XCONS (XCONS (tem1
)->cdr
)->car
))
2240 f
->display
.x
->left_pos
= XINT (XCONS (XCONS (tem1
)->cdr
)->car
);
2242 else if (EQ (tem1
, Qunbound
))
2243 f
->display
.x
->left_pos
= 0;
2246 CHECK_NUMBER (tem1
, 0);
2247 f
->display
.x
->left_pos
= XINT (tem1
);
2248 if (f
->display
.x
->left_pos
< 0)
2249 window_prompting
|= XNegative
;
2252 if (!NILP (tem2
) && ! EQ (tem2
, Qunbound
))
2253 window_prompting
|= USPosition
;
2255 window_prompting
|= PPosition
;
2258 return window_prompting
;
2261 #if !defined (HAVE_X11R4) && !defined (HAVE_XSETWMPROTOCOLS)
2264 XSetWMProtocols (dpy
, w
, protocols
, count
)
2271 prop
= XInternAtom (dpy
, "WM_PROTOCOLS", False
);
2272 if (prop
== None
) return False
;
2273 XChangeProperty (dpy
, w
, prop
, XA_ATOM
, 32, PropModeReplace
,
2274 (unsigned char *) protocols
, count
);
2277 #endif /* not HAVE_X11R4 && not HAVE_XSETWMPROTOCOLS */
2279 #ifdef USE_X_TOOLKIT
2281 /* If the WM_PROTOCOLS property does not already contain WM_TAKE_FOCUS,
2282 WM_DELETE_WINDOW, and WM_SAVE_YOURSELF, then add them. (They may
2283 already be present because of the toolkit (Motif adds some of them,
2284 for example, but Xt doesn't). */
2287 hack_wm_protocols (f
, widget
)
2291 Display
*dpy
= XtDisplay (widget
);
2292 Window w
= XtWindow (widget
);
2293 int need_delete
= 1;
2299 Atom type
, *atoms
= 0;
2301 unsigned long nitems
= 0;
2302 unsigned long bytes_after
;
2304 if ((XGetWindowProperty (dpy
, w
,
2305 FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_protocols
,
2306 0L, 100L, False
, XA_ATOM
,
2307 &type
, &format
, &nitems
, &bytes_after
,
2308 (unsigned char **) &atoms
)
2310 && format
== 32 && type
== XA_ATOM
)
2314 if (atoms
[nitems
] == FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_delete_window
)
2316 else if (atoms
[nitems
] == FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_take_focus
)
2318 else if (atoms
[nitems
] == FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_save_yourself
)
2321 if (atoms
) XFree ((char *) atoms
);
2327 props
[count
++] = FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_delete_window
;
2329 props
[count
++] = FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_take_focus
;
2331 props
[count
++] = FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_save_yourself
;
2333 XChangeProperty (dpy
, w
, FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_protocols
,
2334 XA_ATOM
, 32, PropModeAppend
,
2335 (unsigned char *) props
, count
);
2341 #ifdef USE_X_TOOLKIT
2343 /* Create and set up the X widget for frame F. */
2346 x_window (f
, window_prompting
, minibuffer_only
)
2348 long window_prompting
;
2349 int minibuffer_only
;
2351 XClassHint class_hints
;
2352 XSetWindowAttributes attributes
;
2353 unsigned long attribute_mask
;
2355 Widget shell_widget
;
2357 Widget frame_widget
;
2365 = (STRINGP (f
->name
) ? (char *)XSTRING (f
->name
)->data
: "emacs");
2366 f
->namebuf
= (char *) xrealloc (f
->namebuf
, strlen (str
) + 1);
2367 strcpy (f
->namebuf
, str
);
2371 XtSetArg (al
[ac
], XtNallowShellResize
, 1); ac
++;
2372 XtSetArg (al
[ac
], XtNinput
, 1); ac
++;
2373 XtSetArg (al
[ac
], XtNmappedWhenManaged
, 0); ac
++;
2374 shell_widget
= XtAppCreateShell (f
->namebuf
, EMACS_CLASS
,
2375 topLevelShellWidgetClass
,
2376 FRAME_X_DISPLAY (f
), al
, ac
);
2378 f
->display
.x
->widget
= shell_widget
;
2379 /* maybe_set_screen_title_format (shell_widget); */
2381 pane_widget
= lw_create_widget ("main", "pane", widget_id_tick
++,
2382 (widget_value
*) NULL
,
2383 shell_widget
, False
,
2386 (lw_callback
) NULL
);
2388 f
->display
.x
->column_widget
= pane_widget
;
2390 if (!minibuffer_only
&& FRAME_EXTERNAL_MENU_BAR (f
))
2391 initialize_frame_menubar (f
);
2393 /* mappedWhenManaged to false tells to the paned window to not map/unmap
2394 the emacs screen when changing menubar. This reduces flickering. */
2397 XtSetArg (al
[ac
], XtNmappedWhenManaged
, 0); ac
++;
2398 XtSetArg (al
[ac
], XtNshowGrip
, 0); ac
++;
2399 XtSetArg (al
[ac
], XtNallowResize
, 1); ac
++;
2400 XtSetArg (al
[ac
], XtNresizeToPreferred
, 1); ac
++;
2401 XtSetArg (al
[ac
], XtNemacsFrame
, f
); ac
++;
2402 frame_widget
= XtCreateWidget (f
->namebuf
,
2404 pane_widget
, al
, ac
);
2405 lw_set_main_areas (pane_widget
, f
->display
.x
->menubar_widget
, frame_widget
);
2407 f
->display
.x
->edit_widget
= frame_widget
;
2409 if (f
->display
.x
->menubar_widget
)
2410 XtManageChild (f
->display
.x
->menubar_widget
);
2411 XtManageChild (frame_widget
);
2413 /* Do some needed geometry management. */
2416 char *tem
, shell_position
[32];
2420 = (f
->display
.x
->menubar_widget
2421 ? (f
->display
.x
->menubar_widget
->core
.height
2422 + f
->display
.x
->menubar_widget
->core
.border_width
)
2425 if (FRAME_EXTERNAL_MENU_BAR (f
))
2428 XtVaGetValues (pane_widget
, XtNinternalBorderWidth
, &ibw
, NULL
);
2429 menubar_size
+= ibw
;
2432 /* Convert our geometry parameters into a geometry string
2434 Note that we do not specify here whether the position
2435 is a user-specified or program-specified one.
2436 We pass that information later, in x_wm_set_size_hints. */
2438 int left
= f
->display
.x
->left_pos
;
2439 int xneg
= window_prompting
& XNegative
;
2440 int top
= f
->display
.x
->top_pos
;
2441 int yneg
= window_prompting
& YNegative
;
2447 if (window_prompting
& USPosition
)
2448 sprintf (shell_position
, "=%dx%d%c%d%c%d", PIXEL_WIDTH (f
),
2449 PIXEL_HEIGHT (f
) + menubar_size
,
2450 (xneg
? '-' : '+'), left
,
2451 (yneg
? '-' : '+'), top
);
2453 sprintf (shell_position
, "=%dx%d", PIXEL_WIDTH (f
),
2454 PIXEL_HEIGHT (f
) + menubar_size
);
2457 len
= strlen (shell_position
) + 1;
2458 tem
= (char *) xmalloc (len
);
2459 strncpy (tem
, shell_position
, len
);
2460 XtSetArg (al
[ac
], XtNgeometry
, tem
); ac
++;
2461 XtSetValues (shell_widget
, al
, ac
);
2464 x_calc_absolute_position (f
);
2466 XtManageChild (pane_widget
);
2467 XtRealizeWidget (shell_widget
);
2469 FRAME_X_WINDOW (f
) = XtWindow (frame_widget
);
2471 validate_x_resource_name ();
2472 class_hints
.res_name
= (char *) XSTRING (Vx_resource_name
)->data
;
2473 class_hints
.res_class
= EMACS_CLASS
;
2474 XSetClassHint (FRAME_X_DISPLAY (f
), XtWindow (shell_widget
), &class_hints
);
2476 f
->display
.x
->wm_hints
.input
= True
;
2477 f
->display
.x
->wm_hints
.flags
|= InputHint
;
2478 XSetWMHints (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2479 &f
->display
.x
->wm_hints
);
2481 hack_wm_protocols (f
, shell_widget
);
2484 XtAddEventHandler (shell_widget
, 0, True
, _XEditResCheckMessages
, 0);
2487 /* Do a stupid property change to force the server to generate a
2488 propertyNotify event so that the event_stream server timestamp will
2489 be initialized to something relevant to the time we created the window.
2491 XChangeProperty (XtDisplay (frame_widget
), XtWindow (frame_widget
),
2492 FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_protocols
,
2493 XA_ATOM
, 32, PropModeAppend
,
2494 (unsigned char*) NULL
, 0);
2496 /* Make all the standard events reach the Emacs frame. */
2497 attributes
.event_mask
= STANDARD_EVENT_SET
;
2498 attribute_mask
= CWEventMask
;
2499 XChangeWindowAttributes (XtDisplay (shell_widget
), XtWindow (shell_widget
),
2500 attribute_mask
, &attributes
);
2502 XtMapWidget (frame_widget
);
2504 /* x_set_name normally ignores requests to set the name if the
2505 requested name is the same as the current name. This is the one
2506 place where that assumption isn't correct; f->name is set, but
2507 the X server hasn't been told. */
2510 int explicit = f
->explicit_name
;
2512 f
->explicit_name
= 0;
2515 x_set_name (f
, name
, explicit);
2518 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2519 f
->display
.x
->text_cursor
);
2521 /* If we have a program-specified position, communicate it to
2522 the window manager thus. */
2523 if (FRAME_X_WINDOW (f
))
2524 XMoveWindow (FRAME_X_DISPLAY (f
), XtWindow (f
->display
.x
->widget
),
2525 f
->display
.x
->left_pos
, f
->display
.x
->top_pos
);
2529 if (FRAME_X_WINDOW (f
) == 0)
2530 error ("Unable to create window");
2533 #else /* not USE_X_TOOLKIT */
2535 /* Create and set up the X window for frame F. */
2541 XClassHint class_hints
;
2542 XSetWindowAttributes attributes
;
2543 unsigned long attribute_mask
;
2545 attributes
.background_pixel
= f
->display
.x
->background_pixel
;
2546 attributes
.border_pixel
= f
->display
.x
->border_pixel
;
2547 attributes
.bit_gravity
= StaticGravity
;
2548 attributes
.backing_store
= NotUseful
;
2549 attributes
.save_under
= True
;
2550 attributes
.event_mask
= STANDARD_EVENT_SET
;
2551 attribute_mask
= (CWBackPixel
| CWBorderPixel
| CWBitGravity
2553 | CWBackingStore
| CWSaveUnder
2559 = XCreateWindow (FRAME_X_DISPLAY (f
),
2560 f
->display
.x
->parent_desc
,
2561 f
->display
.x
->left_pos
,
2562 f
->display
.x
->top_pos
,
2563 PIXEL_WIDTH (f
), PIXEL_HEIGHT (f
),
2564 f
->display
.x
->border_width
,
2565 CopyFromParent
, /* depth */
2566 InputOutput
, /* class */
2567 FRAME_X_DISPLAY_INFO (f
)->visual
,
2568 attribute_mask
, &attributes
);
2570 validate_x_resource_name ();
2571 class_hints
.res_name
= (char *) XSTRING (Vx_resource_name
)->data
;
2572 class_hints
.res_class
= EMACS_CLASS
;
2573 XSetClassHint (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), &class_hints
);
2575 /* This indicates that we use the "Passive Input" input model.
2576 Unless we do this, we don't get the Focus{In,Out} events that we
2577 need to draw the cursor correctly. Accursed bureaucrats.
2578 XWhipsAndChains (FRAME_X_DISPLAY (f), IronMaiden, &TheRack); */
2580 f
->display
.x
->wm_hints
.input
= True
;
2581 f
->display
.x
->wm_hints
.flags
|= InputHint
;
2582 XSetWMHints (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2583 &f
->display
.x
->wm_hints
);
2585 /* Request "save yourself" and "delete window" commands from wm. */
2588 protocols
[0] = FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_delete_window
;
2589 protocols
[1] = FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_save_yourself
;
2590 XSetWMProtocols (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), protocols
, 2);
2593 /* x_set_name normally ignores requests to set the name if the
2594 requested name is the same as the current name. This is the one
2595 place where that assumption isn't correct; f->name is set, but
2596 the X server hasn't been told. */
2599 int explicit = f
->explicit_name
;
2601 f
->explicit_name
= 0;
2604 x_set_name (f
, name
, explicit);
2607 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2608 f
->display
.x
->text_cursor
);
2612 if (FRAME_X_WINDOW (f
) == 0)
2613 error ("Unable to create window");
2616 #endif /* not USE_X_TOOLKIT */
2618 /* Handle the icon stuff for this window. Perhaps later we might
2619 want an x_set_icon_position which can be called interactively as
2627 Lisp_Object icon_x
, icon_y
;
2629 /* Set the position of the icon. Note that twm groups all
2630 icons in an icon window. */
2631 icon_x
= x_get_arg (parms
, Qicon_left
, 0, 0, number
);
2632 icon_y
= x_get_arg (parms
, Qicon_top
, 0, 0, number
);
2633 if (!EQ (icon_x
, Qunbound
) && !EQ (icon_y
, Qunbound
))
2635 CHECK_NUMBER (icon_x
, 0);
2636 CHECK_NUMBER (icon_y
, 0);
2638 else if (!EQ (icon_x
, Qunbound
) || !EQ (icon_y
, Qunbound
))
2639 error ("Both left and top icon corners of icon must be specified");
2643 if (! EQ (icon_x
, Qunbound
))
2644 x_wm_set_icon_position (f
, XINT (icon_x
), XINT (icon_y
));
2646 /* Start up iconic or window? */
2647 x_wm_set_window_state
2648 (f
, (EQ (x_get_arg (parms
, Qvisibility
, 0, 0, symbol
), Qicon
)
2655 /* Make the GC's needed for this window, setting the
2656 background, border and mouse colors; also create the
2657 mouse cursor and the gray border tile. */
2659 static char cursor_bits
[] =
2661 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2662 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2663 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2664 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
2671 XGCValues gc_values
;
2677 /* Create the GC's of this frame.
2678 Note that many default values are used. */
2681 gc_values
.font
= f
->display
.x
->font
->fid
;
2682 gc_values
.foreground
= f
->display
.x
->foreground_pixel
;
2683 gc_values
.background
= f
->display
.x
->background_pixel
;
2684 gc_values
.line_width
= 0; /* Means 1 using fast algorithm. */
2685 f
->display
.x
->normal_gc
= XCreateGC (FRAME_X_DISPLAY (f
),
2687 GCLineWidth
| GCFont
2688 | GCForeground
| GCBackground
,
2691 /* Reverse video style. */
2692 gc_values
.foreground
= f
->display
.x
->background_pixel
;
2693 gc_values
.background
= f
->display
.x
->foreground_pixel
;
2694 f
->display
.x
->reverse_gc
= XCreateGC (FRAME_X_DISPLAY (f
),
2696 GCFont
| GCForeground
| GCBackground
2700 /* Cursor has cursor-color background, background-color foreground. */
2701 gc_values
.foreground
= f
->display
.x
->background_pixel
;
2702 gc_values
.background
= f
->display
.x
->cursor_pixel
;
2703 gc_values
.fill_style
= FillOpaqueStippled
;
2705 = XCreateBitmapFromData (FRAME_X_DISPLAY (f
),
2706 FRAME_X_DISPLAY_INFO (f
)->root_window
,
2707 cursor_bits
, 16, 16);
2708 f
->display
.x
->cursor_gc
2709 = XCreateGC (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2710 (GCFont
| GCForeground
| GCBackground
2711 | GCFillStyle
| GCStipple
| GCLineWidth
),
2714 /* Create the gray border tile used when the pointer is not in
2715 the frame. Since this depends on the frame's pixel values,
2716 this must be done on a per-frame basis. */
2717 f
->display
.x
->border_tile
2718 = (XCreatePixmapFromBitmapData
2719 (FRAME_X_DISPLAY (f
), FRAME_X_DISPLAY_INFO (f
)->root_window
,
2720 gray_bits
, gray_width
, gray_height
,
2721 f
->display
.x
->foreground_pixel
,
2722 f
->display
.x
->background_pixel
,
2723 DefaultDepth (FRAME_X_DISPLAY (f
),
2724 XScreenNumberOfScreen (FRAME_X_SCREEN (f
)))));
2729 DEFUN ("x-create-frame", Fx_create_frame
, Sx_create_frame
,
2731 "Make a new X window, which is called a \"frame\" in Emacs terms.\n\
2732 Returns an Emacs frame object.\n\
2733 ALIST is an alist of frame parameters.\n\
2734 If the parameters specify that the frame should not have a minibuffer,\n\
2735 and do not specify a specific minibuffer window to use,\n\
2736 then `default-minibuffer-frame' must be a frame whose minibuffer can\n\
2737 be shared by the new frame.\n\
2739 This function is an internal primitive--use `make-frame' instead.")
2744 Lisp_Object frame
, tem
;
2746 int minibuffer_only
= 0;
2747 long window_prompting
= 0;
2749 int count
= specpdl_ptr
- specpdl
;
2750 struct gcpro gcpro1
;
2751 Lisp_Object display
;
2752 struct x_display_info
*dpyinfo
;
2758 display
= x_get_arg (parms
, Qdisplay
, 0, 0, 0);
2759 if (EQ (display
, Qunbound
))
2761 dpyinfo
= check_x_display_info (display
);
2763 kb
= dpyinfo
->kboard
;
2765 kb
= &the_only_kboard
;
2768 name
= x_get_arg (parms
, Qname
, "title", "Title", string
);
2770 && ! EQ (name
, Qunbound
)
2772 error ("Invalid frame name--not a string or nil");
2774 /* See if parent window is specified. */
2775 parent
= x_get_arg (parms
, Qparent_id
, NULL
, NULL
, number
);
2776 if (EQ (parent
, Qunbound
))
2778 if (! NILP (parent
))
2779 CHECK_NUMBER (parent
, 0);
2781 tem
= x_get_arg (parms
, Qminibuffer
, 0, 0, symbol
);
2782 if (EQ (tem
, Qnone
) || NILP (tem
))
2783 f
= make_frame_without_minibuffer (Qnil
, kb
);
2784 else if (EQ (tem
, Qonly
))
2786 f
= make_minibuffer_frame ();
2787 minibuffer_only
= 1;
2789 else if (WINDOWP (tem
))
2790 f
= make_frame_without_minibuffer (tem
, kb
);
2794 /* Note that X Windows does support scroll bars. */
2795 FRAME_CAN_HAVE_SCROLL_BARS (f
) = 1;
2797 XSETFRAME (frame
, f
);
2800 f
->output_method
= output_x_window
;
2801 f
->display
.x
= (struct x_display
*) xmalloc (sizeof (struct x_display
));
2802 bzero (f
->display
.x
, sizeof (struct x_display
));
2803 f
->display
.x
->icon_bitmap
= -1;
2805 FRAME_X_DISPLAY_INFO (f
) = dpyinfo
;
2807 FRAME_KBOARD (f
) = kb
;
2810 /* Specify the parent under which to make this X window. */
2814 f
->display
.x
->parent_desc
= parent
;
2815 f
->display
.x
->explicit_parent
= 1;
2819 f
->display
.x
->parent_desc
= FRAME_X_DISPLAY_INFO (f
)->root_window
;
2820 f
->display
.x
->explicit_parent
= 0;
2823 /* Note that the frame has no physical cursor right now. */
2824 f
->phys_cursor_x
= -1;
2826 /* Set the name; the functions to which we pass f expect the name to
2828 if (EQ (name
, Qunbound
) || NILP (name
))
2830 f
->name
= build_string (dpyinfo
->x_id_name
);
2831 f
->explicit_name
= 0;
2836 f
->explicit_name
= 1;
2837 /* use the frame's title when getting resources for this frame. */
2838 specbind (Qx_resource_name
, name
);
2841 /* Extract the window parameters from the supplied values
2842 that are needed to determine window geometry. */
2846 font
= x_get_arg (parms
, Qfont
, "font", "Font", string
);
2848 /* First, try whatever font the caller has specified. */
2850 font
= x_new_font (f
, XSTRING (font
)->data
);
2851 /* Try out a font which we hope has bold and italic variations. */
2852 if (!STRINGP (font
))
2853 font
= x_new_font (f
, "-misc-fixed-medium-r-normal-*-*-140-*-*-c-*-iso8859-1");
2854 if (! STRINGP (font
))
2855 font
= x_new_font (f
, "-*-*-medium-r-normal-*-*-140-*-*-c-*-iso8859-1");
2856 if (! STRINGP (font
))
2857 /* This was formerly the first thing tried, but it finds too many fonts
2858 and takes too long. */
2859 font
= x_new_font (f
, "-*-*-medium-r-*-*-*-*-*-*-c-*-iso8859-1");
2860 /* If those didn't work, look for something which will at least work. */
2861 if (! STRINGP (font
))
2862 font
= x_new_font (f
, "-*-fixed-*-*-*-*-*-140-*-*-c-*-iso8859-1");
2864 if (! STRINGP (font
))
2865 font
= build_string ("fixed");
2867 x_default_parameter (f
, parms
, Qfont
, font
,
2868 "font", "Font", string
);
2871 #ifdef USE_X_TOOLKIT
2872 /* Prevent lwlib/xlwmenu.c from crashing because of a bug
2873 whereby it fails to get any font. */
2874 xlwmenu_default_font
= f
->display
.x
->font
;
2877 x_default_parameter (f
, parms
, Qborder_width
, make_number (2),
2878 "borderwidth", "BorderWidth", number
);
2879 /* This defaults to 2 in order to match xterm. We recognize either
2880 internalBorderWidth or internalBorder (which is what xterm calls
2882 if (NILP (Fassq (Qinternal_border_width
, parms
)))
2886 value
= x_get_arg (parms
, Qinternal_border_width
,
2887 "internalBorder", "BorderWidth", number
);
2888 if (! EQ (value
, Qunbound
))
2889 parms
= Fcons (Fcons (Qinternal_border_width
, value
),
2892 x_default_parameter (f
, parms
, Qinternal_border_width
, make_number (2),
2893 "internalBorderWidth", "BorderWidth", number
);
2894 x_default_parameter (f
, parms
, Qvertical_scroll_bars
, Qt
,
2895 "verticalScrollBars", "ScrollBars", boolean
);
2897 /* Also do the stuff which must be set before the window exists. */
2898 x_default_parameter (f
, parms
, Qforeground_color
, build_string ("black"),
2899 "foreground", "Foreground", string
);
2900 x_default_parameter (f
, parms
, Qbackground_color
, build_string ("white"),
2901 "background", "Background", string
);
2902 x_default_parameter (f
, parms
, Qmouse_color
, build_string ("black"),
2903 "pointerColor", "Foreground", string
);
2904 x_default_parameter (f
, parms
, Qcursor_color
, build_string ("black"),
2905 "cursorColor", "Foreground", string
);
2906 x_default_parameter (f
, parms
, Qborder_color
, build_string ("black"),
2907 "borderColor", "BorderColor", string
);
2909 x_default_parameter (f
, parms
, Qmenu_bar_lines
, make_number (1),
2910 "menuBar", "MenuBar", number
);
2911 x_default_parameter (f
, parms
, Qscroll_bar_width
, Qnil
,
2912 "scrollBarWidth", "ScrollBarWidth", number
);
2914 f
->display
.x
->parent_desc
= FRAME_X_DISPLAY_INFO (f
)->root_window
;
2915 window_prompting
= x_figure_window_size (f
, parms
);
2917 if (window_prompting
& XNegative
)
2919 if (window_prompting
& YNegative
)
2920 f
->display
.x
->win_gravity
= SouthEastGravity
;
2922 f
->display
.x
->win_gravity
= NorthEastGravity
;
2926 if (window_prompting
& YNegative
)
2927 f
->display
.x
->win_gravity
= SouthWestGravity
;
2929 f
->display
.x
->win_gravity
= NorthWestGravity
;
2932 f
->display
.x
->size_hint_flags
= window_prompting
;
2934 #ifdef USE_X_TOOLKIT
2935 x_window (f
, window_prompting
, minibuffer_only
);
2941 init_frame_faces (f
);
2943 /* We need to do this after creating the X window, so that the
2944 icon-creation functions can say whose icon they're describing. */
2945 x_default_parameter (f
, parms
, Qicon_type
, Qnil
,
2946 "bitmapIcon", "BitmapIcon", symbol
);
2948 x_default_parameter (f
, parms
, Qauto_raise
, Qnil
,
2949 "autoRaise", "AutoRaiseLower", boolean
);
2950 x_default_parameter (f
, parms
, Qauto_lower
, Qnil
,
2951 "autoLower", "AutoRaiseLower", boolean
);
2952 x_default_parameter (f
, parms
, Qcursor_type
, Qbox
,
2953 "cursorType", "CursorType", symbol
);
2955 /* Dimensions, especially f->height, must be done via change_frame_size.
2956 Change will not be effected unless different from the current
2960 f
->height
= f
->width
= 0;
2961 change_frame_size (f
, height
, width
, 1, 0);
2963 /* Tell the server what size and position, etc, we want,
2964 and how badly we want them. */
2966 x_wm_set_size_hint (f
, window_prompting
, 0);
2969 tem
= x_get_arg (parms
, Qunsplittable
, 0, 0, boolean
);
2970 f
->no_split
= minibuffer_only
|| EQ (tem
, Qt
);
2974 /* It is now ok to make the frame official
2975 even if we get an error below.
2976 And the frame needs to be on Vframe_list
2977 or making it visible won't work. */
2978 Vframe_list
= Fcons (frame
, Vframe_list
);
2980 /* Now that the frame is official, it counts as a reference to
2982 FRAME_X_DISPLAY_INFO (f
)->reference_count
++;
2984 /* Make the window appear on the frame and enable display,
2985 unless the caller says not to. However, with explicit parent,
2986 Emacs cannot control visibility, so don't try. */
2987 if (! f
->display
.x
->explicit_parent
)
2989 Lisp_Object visibility
;
2991 visibility
= x_get_arg (parms
, Qvisibility
, 0, 0, symbol
);
2992 if (EQ (visibility
, Qunbound
))
2995 if (EQ (visibility
, Qicon
))
2996 x_iconify_frame (f
);
2997 else if (! NILP (visibility
))
2998 x_make_frame_visible (f
);
3000 /* Must have been Qnil. */
3004 return unbind_to (count
, frame
);
3007 /* FRAME is used only to get a handle on the X display. We don't pass the
3008 display info directly because we're called from frame.c, which doesn't
3009 know about that structure. */
3011 x_get_focus_frame (frame
)
3012 struct frame
*frame
;
3014 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (frame
);
3016 if (! dpyinfo
->x_focus_frame
)
3019 XSETFRAME (xfocus
, dpyinfo
->x_focus_frame
);
3023 DEFUN ("focus-frame", Ffocus_frame
, Sfocus_frame
, 1, 1, 0,
3024 "Set the focus on FRAME.")
3028 CHECK_LIVE_FRAME (frame
, 0);
3030 if (FRAME_X_P (XFRAME (frame
)))
3033 x_focus_on_frame (XFRAME (frame
));
3041 DEFUN ("unfocus-frame", Funfocus_frame
, Sunfocus_frame
, 0, 0, 0,
3042 "If a frame has been focused, release it.")
3045 if (FRAME_X_P (selected_frame
))
3047 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (selected_frame
);
3049 if (dpyinfo
->x_focus_frame
)
3052 x_unfocus_frame (dpyinfo
->x_focus_frame
);
3060 DEFUN ("x-list-fonts", Fx_list_fonts
, Sx_list_fonts
, 1, 3, 0,
3061 "Return a list of the names of available fonts matching PATTERN.\n\
3062 If optional arguments FACE and FRAME are specified, return only fonts\n\
3063 the same size as FACE on FRAME.\n\
3065 PATTERN is a string, perhaps with wildcard characters;\n\
3066 the * character matches any substring, and\n\
3067 the ? character matches any single character.\n\
3068 PATTERN is case-insensitive.\n\
3069 FACE is a face name--a symbol.\n\
3071 The return value is a list of strings, suitable as arguments to\n\
3074 Fonts Emacs can't use (i.e. proportional fonts) may or may not be excluded\n\
3075 even if they match PATTERN and FACE.")
3076 (pattern
, face
, frame
)
3077 Lisp_Object pattern
, face
, frame
;
3081 #ifndef BROKEN_XLISTFONTSWITHINFO
3084 XFontStruct
*size_ref
;
3089 CHECK_STRING (pattern
, 0);
3091 CHECK_SYMBOL (face
, 1);
3093 f
= check_x_frame (frame
);
3095 /* Determine the width standard for comparison with the fonts we find. */
3103 /* Don't die if we get called with a terminal frame. */
3104 if (! FRAME_X_P (f
))
3105 error ("non-X frame used in `x-list-fonts'");
3107 face_id
= face_name_id_number (f
, face
);
3109 if (face_id
< 0 || face_id
>= FRAME_N_PARAM_FACES (f
)
3110 || FRAME_PARAM_FACES (f
) [face_id
] == 0)
3111 size_ref
= f
->display
.x
->font
;
3114 size_ref
= FRAME_PARAM_FACES (f
) [face_id
]->font
;
3115 if (size_ref
== (XFontStruct
*) (~0))
3116 size_ref
= f
->display
.x
->font
;
3120 /* See if we cached the result for this particular query. */
3121 list
= Fassoc (pattern
,
3122 XCONS (FRAME_X_DISPLAY_INFO (f
)->name_list_element
)->cdr
);
3124 /* We have info in the cache for this PATTERN. */
3127 Lisp_Object tem
, newlist
;
3129 /* We have info about this pattern. */
3130 list
= XCONS (list
)->cdr
;
3137 /* Filter the cached info and return just the fonts that match FACE. */
3139 for (tem
= list
; CONSP (tem
); tem
= XCONS (tem
)->cdr
)
3141 XFontStruct
*thisinfo
;
3143 thisinfo
= XLoadQueryFont (FRAME_X_DISPLAY (f
),
3144 XSTRING (XCONS (tem
)->car
)->data
);
3146 if (thisinfo
&& same_size_fonts (thisinfo
, size_ref
))
3147 newlist
= Fcons (XCONS (tem
)->car
, newlist
);
3149 XFreeFont (FRAME_X_DISPLAY (f
), thisinfo
);
3159 /* Solaris 2.3 has a bug in XListFontsWithInfo. */
3160 #ifndef BROKEN_XLISTFONTSWITHINFO
3162 names
= XListFontsWithInfo (FRAME_X_DISPLAY (f
),
3163 XSTRING (pattern
)->data
,
3164 2000, /* maxnames */
3165 &num_fonts
, /* count_return */
3166 &info
); /* info_return */
3169 names
= XListFonts (FRAME_X_DISPLAY (f
),
3170 XSTRING (pattern
)->data
,
3171 2000, /* maxnames */
3172 &num_fonts
); /* count_return */
3181 Lisp_Object full_list
;
3183 /* Make a list of all the fonts we got back.
3184 Store that in the font cache for the display. */
3186 for (i
= 0; i
< num_fonts
; i
++)
3187 full_list
= Fcons (build_string (names
[i
]), full_list
);
3188 XCONS (FRAME_X_DISPLAY_INFO (f
)->name_list_element
)->cdr
3189 = Fcons (Fcons (pattern
, full_list
),
3190 XCONS (FRAME_X_DISPLAY_INFO (f
)->name_list_element
)->cdr
);
3192 /* Make a list of the fonts that have the right width. */
3194 for (i
= 0; i
< num_fonts
; i
++)
3202 #ifdef BROKEN_XLISTFONTSWITHINFO
3203 XFontStruct
*thisinfo
;
3206 thisinfo
= XLoadQueryFont (FRAME_X_DISPLAY (f
), names
[i
]);
3209 keeper
= thisinfo
&& same_size_fonts (thisinfo
, size_ref
);
3211 keeper
= same_size_fonts (&info
[i
], size_ref
);
3215 list
= Fcons (build_string (names
[i
]), list
);
3217 list
= Fnreverse (list
);
3220 #ifndef BROKEN_XLISTFONTSWITHINFO
3222 XFreeFontInfo (names
, info
, num_fonts
);
3225 XFreeFontNames (names
);
3233 DEFUN ("x-color-defined-p", Fx_color_defined_p
, Sx_color_defined_p
, 1, 2, 0,
3234 "Return non-nil if color COLOR is supported on frame FRAME.\n\
3235 If FRAME is omitted or nil, use the selected frame.")
3237 Lisp_Object color
, frame
;
3240 FRAME_PTR f
= check_x_frame (frame
);
3242 CHECK_STRING (color
, 1);
3244 if (defined_color (f
, XSTRING (color
)->data
, &foo
, 0))
3250 DEFUN ("x-color-values", Fx_color_values
, Sx_color_values
, 1, 2, 0,
3251 "Return a description of the color named COLOR on frame FRAME.\n\
3252 The value is a list of integer RGB values--(RED GREEN BLUE).\n\
3253 These values appear to range from 0 to 65280 or 65535, depending\n\
3254 on the system; white is (65280 65280 65280) or (65535 65535 65535).\n\
3255 If FRAME is omitted or nil, use the selected frame.")
3257 Lisp_Object color
, frame
;
3260 FRAME_PTR f
= check_x_frame (frame
);
3262 CHECK_STRING (color
, 1);
3264 if (defined_color (f
, XSTRING (color
)->data
, &foo
, 0))
3268 rgb
[0] = make_number (foo
.red
);
3269 rgb
[1] = make_number (foo
.green
);
3270 rgb
[2] = make_number (foo
.blue
);
3271 return Flist (3, rgb
);
3277 DEFUN ("x-display-color-p", Fx_display_color_p
, Sx_display_color_p
, 0, 1, 0,
3278 "Return t if the X display supports color.\n\
3279 The optional argument DISPLAY specifies which display to ask about.\n\
3280 DISPLAY should be either a frame or a display name (a string).\n\
3281 If omitted or nil, that stands for the selected frame's display.")
3283 Lisp_Object display
;
3285 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3287 if (dpyinfo
->n_planes
<= 2)
3290 switch (dpyinfo
->visual
->class)
3303 DEFUN ("x-display-grayscale-p", Fx_display_grayscale_p
, Sx_display_grayscale_p
,
3305 "Return t if the X display supports shades of gray.\n\
3306 The optional argument DISPLAY specifies which display to ask about.\n\
3307 DISPLAY should be either a frame or a display name (a string).\n\
3308 If omitted or nil, that stands for the selected frame's display.")
3310 Lisp_Object display
;
3312 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3314 if (dpyinfo
->n_planes
<= 2)
3317 return (dpyinfo
->n_planes
> 1
3318 && (dpyinfo
->visual
->class == StaticGray
3319 || dpyinfo
->visual
->class == GrayScale
));
3322 DEFUN ("x-display-pixel-width", Fx_display_pixel_width
, Sx_display_pixel_width
,
3324 "Returns the width in pixels of the X display DISPLAY.\n\
3325 The optional argument DISPLAY specifies which display to ask about.\n\
3326 DISPLAY should be either a frame or a display name (a string).\n\
3327 If omitted or nil, that stands for the selected frame's display.")
3329 Lisp_Object display
;
3331 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3333 return make_number (dpyinfo
->width
);
3336 DEFUN ("x-display-pixel-height", Fx_display_pixel_height
,
3337 Sx_display_pixel_height
, 0, 1, 0,
3338 "Returns the height in pixels of the X display DISPLAY.\n\
3339 The optional argument DISPLAY specifies which display to ask about.\n\
3340 DISPLAY should be either a frame or a display name (a string).\n\
3341 If omitted or nil, that stands for the selected frame's display.")
3343 Lisp_Object display
;
3345 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3347 return make_number (dpyinfo
->height
);
3350 DEFUN ("x-display-planes", Fx_display_planes
, Sx_display_planes
,
3352 "Returns the number of bitplanes of the X display DISPLAY.\n\
3353 The optional argument DISPLAY specifies which display to ask about.\n\
3354 DISPLAY should be either a frame or a display name (a string).\n\
3355 If omitted or nil, that stands for the selected frame's display.")
3357 Lisp_Object display
;
3359 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3361 return make_number (dpyinfo
->n_planes
);
3364 DEFUN ("x-display-color-cells", Fx_display_color_cells
, Sx_display_color_cells
,
3366 "Returns the number of color cells of the X display DISPLAY.\n\
3367 The optional argument DISPLAY specifies which display to ask about.\n\
3368 DISPLAY should be either a frame or a display name (a string).\n\
3369 If omitted or nil, that stands for the selected frame's display.")
3371 Lisp_Object display
;
3373 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3375 return make_number (DisplayCells (dpyinfo
->display
,
3376 XScreenNumberOfScreen (dpyinfo
->screen
)));
3379 DEFUN ("x-server-max-request-size", Fx_server_max_request_size
,
3380 Sx_server_max_request_size
,
3382 "Returns the maximum request size of the X server of display DISPLAY.\n\
3383 The optional argument DISPLAY specifies which display to ask about.\n\
3384 DISPLAY should be either a frame or a display name (a string).\n\
3385 If omitted or nil, that stands for the selected frame's display.")
3387 Lisp_Object display
;
3389 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3391 return make_number (MAXREQUEST (dpyinfo
->display
));
3394 DEFUN ("x-server-vendor", Fx_server_vendor
, Sx_server_vendor
, 0, 1, 0,
3395 "Returns the vendor ID string of the X server of display DISPLAY.\n\
3396 The optional argument DISPLAY specifies which display to ask about.\n\
3397 DISPLAY should be either a frame or a display name (a string).\n\
3398 If omitted or nil, that stands for the selected frame's display.")
3400 Lisp_Object display
;
3402 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3403 char *vendor
= ServerVendor (dpyinfo
->display
);
3405 if (! vendor
) vendor
= "";
3406 return build_string (vendor
);
3409 DEFUN ("x-server-version", Fx_server_version
, Sx_server_version
, 0, 1, 0,
3410 "Returns the version numbers of the X server of display DISPLAY.\n\
3411 The value is a list of three integers: the major and minor\n\
3412 version numbers of the X Protocol in use, and the vendor-specific release\n\
3413 number. See also the function `x-server-vendor'.\n\n\
3414 The optional argument DISPLAY specifies which display to ask about.\n\
3415 DISPLAY should be either a frame or a display name (a string).\n\
3416 If omitted or nil, that stands for the selected frame's display.")
3418 Lisp_Object display
;
3420 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3421 Display
*dpy
= dpyinfo
->display
;
3423 return Fcons (make_number (ProtocolVersion (dpy
)),
3424 Fcons (make_number (ProtocolRevision (dpy
)),
3425 Fcons (make_number (VendorRelease (dpy
)), Qnil
)));
3428 DEFUN ("x-display-screens", Fx_display_screens
, Sx_display_screens
, 0, 1, 0,
3429 "Returns the number of screens on the X server of display DISPLAY.\n\
3430 The optional argument DISPLAY specifies which display to ask about.\n\
3431 DISPLAY should be either a frame or a display name (a string).\n\
3432 If omitted or nil, that stands for the selected frame's display.")
3434 Lisp_Object display
;
3436 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3438 return make_number (ScreenCount (dpyinfo
->display
));
3441 DEFUN ("x-display-mm-height", Fx_display_mm_height
, Sx_display_mm_height
, 0, 1, 0,
3442 "Returns the height in millimeters of the X display DISPLAY.\n\
3443 The optional argument DISPLAY specifies which display to ask about.\n\
3444 DISPLAY should be either a frame or a display name (a string).\n\
3445 If omitted or nil, that stands for the selected frame's display.")
3447 Lisp_Object display
;
3449 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3451 return make_number (HeightMMOfScreen (dpyinfo
->screen
));
3454 DEFUN ("x-display-mm-width", Fx_display_mm_width
, Sx_display_mm_width
, 0, 1, 0,
3455 "Returns the width in millimeters of the X display DISPLAY.\n\
3456 The optional argument DISPLAY specifies which display to ask about.\n\
3457 DISPLAY should be either a frame or a display name (a string).\n\
3458 If omitted or nil, that stands for the selected frame's display.")
3460 Lisp_Object display
;
3462 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3464 return make_number (WidthMMOfScreen (dpyinfo
->screen
));
3467 DEFUN ("x-display-backing-store", Fx_display_backing_store
,
3468 Sx_display_backing_store
, 0, 1, 0,
3469 "Returns an indication of whether X display DISPLAY does backing store.\n\
3470 The value may be `always', `when-mapped', or `not-useful'.\n\
3471 The optional argument DISPLAY specifies which display to ask about.\n\
3472 DISPLAY should be either a frame or a display name (a string).\n\
3473 If omitted or nil, that stands for the selected frame's display.")
3475 Lisp_Object display
;
3477 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3479 switch (DoesBackingStore (dpyinfo
->screen
))
3482 return intern ("always");
3485 return intern ("when-mapped");
3488 return intern ("not-useful");
3491 error ("Strange value for BackingStore parameter of screen");
3495 DEFUN ("x-display-visual-class", Fx_display_visual_class
,
3496 Sx_display_visual_class
, 0, 1, 0,
3497 "Returns the visual class of the X display DISPLAY.\n\
3498 The value is one of the symbols `static-gray', `gray-scale',\n\
3499 `static-color', `pseudo-color', `true-color', or `direct-color'.\n\n\
3500 The optional argument DISPLAY specifies which display to ask about.\n\
3501 DISPLAY should be either a frame or a display name (a string).\n\
3502 If omitted or nil, that stands for the selected frame's display.")
3504 Lisp_Object display
;
3506 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3508 switch (dpyinfo
->visual
->class)
3510 case StaticGray
: return (intern ("static-gray"));
3511 case GrayScale
: return (intern ("gray-scale"));
3512 case StaticColor
: return (intern ("static-color"));
3513 case PseudoColor
: return (intern ("pseudo-color"));
3514 case TrueColor
: return (intern ("true-color"));
3515 case DirectColor
: return (intern ("direct-color"));
3517 error ("Display has an unknown visual class");
3521 DEFUN ("x-display-save-under", Fx_display_save_under
,
3522 Sx_display_save_under
, 0, 1, 0,
3523 "Returns t if the X display DISPLAY supports the save-under feature.\n\
3524 The optional argument DISPLAY specifies which display to ask about.\n\
3525 DISPLAY should be either a frame or a display name (a string).\n\
3526 If omitted or nil, that stands for the selected frame's display.")
3528 Lisp_Object display
;
3530 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3532 if (DoesSaveUnders (dpyinfo
->screen
) == True
)
3540 register struct frame
*f
;
3542 return PIXEL_WIDTH (f
);
3547 register struct frame
*f
;
3549 return PIXEL_HEIGHT (f
);
3554 register struct frame
*f
;
3556 return FONT_WIDTH (f
->display
.x
->font
);
3561 register struct frame
*f
;
3563 return f
->display
.x
->line_height
;
3567 x_screen_planes (frame
)
3570 return FRAME_X_DISPLAY_INFO (XFRAME (frame
))->n_planes
;
3573 #if 0 /* These no longer seem like the right way to do things. */
3575 /* Draw a rectangle on the frame with left top corner including
3576 the character specified by LEFT_CHAR and TOP_CHAR. The rectangle is
3577 CHARS by LINES wide and long and is the color of the cursor. */
3580 x_rectangle (f
, gc
, left_char
, top_char
, chars
, lines
)
3581 register struct frame
*f
;
3583 register int top_char
, left_char
, chars
, lines
;
3587 int left
= (left_char
* FONT_WIDTH (f
->display
.x
->font
)
3588 + f
->display
.x
->internal_border_width
);
3589 int top
= (top_char
* f
->display
.x
->line_height
3590 + f
->display
.x
->internal_border_width
);
3593 width
= FONT_WIDTH (f
->display
.x
->font
) / 2;
3595 width
= FONT_WIDTH (f
->display
.x
->font
) * chars
;
3597 height
= f
->display
.x
->line_height
/ 2;
3599 height
= f
->display
.x
->line_height
* lines
;
3601 XDrawRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3602 gc
, left
, top
, width
, height
);
3605 DEFUN ("x-draw-rectangle", Fx_draw_rectangle
, Sx_draw_rectangle
, 5, 5, 0,
3606 "Draw a rectangle on FRAME between coordinates specified by\n\
3607 numbers X0, Y0, X1, Y1 in the cursor pixel.")
3608 (frame
, X0
, Y0
, X1
, Y1
)
3609 register Lisp_Object frame
, X0
, X1
, Y0
, Y1
;
3611 register int x0
, y0
, x1
, y1
, top
, left
, n_chars
, n_lines
;
3613 CHECK_LIVE_FRAME (frame
, 0);
3614 CHECK_NUMBER (X0
, 0);
3615 CHECK_NUMBER (Y0
, 1);
3616 CHECK_NUMBER (X1
, 2);
3617 CHECK_NUMBER (Y1
, 3);
3627 n_lines
= y1
- y0
+ 1;
3632 n_lines
= y0
- y1
+ 1;
3638 n_chars
= x1
- x0
+ 1;
3643 n_chars
= x0
- x1
+ 1;
3647 x_rectangle (XFRAME (frame
), XFRAME (frame
)->display
.x
->cursor_gc
,
3648 left
, top
, n_chars
, n_lines
);
3654 DEFUN ("x-erase-rectangle", Fx_erase_rectangle
, Sx_erase_rectangle
, 5, 5, 0,
3655 "Draw a rectangle drawn on FRAME between coordinates\n\
3656 X0, Y0, X1, Y1 in the regular background-pixel.")
3657 (frame
, X0
, Y0
, X1
, Y1
)
3658 register Lisp_Object frame
, X0
, Y0
, X1
, Y1
;
3660 register int x0
, y0
, x1
, y1
, top
, left
, n_chars
, n_lines
;
3662 CHECK_LIVE_FRAME (frame
, 0);
3663 CHECK_NUMBER (X0
, 0);
3664 CHECK_NUMBER (Y0
, 1);
3665 CHECK_NUMBER (X1
, 2);
3666 CHECK_NUMBER (Y1
, 3);
3676 n_lines
= y1
- y0
+ 1;
3681 n_lines
= y0
- y1
+ 1;
3687 n_chars
= x1
- x0
+ 1;
3692 n_chars
= x0
- x1
+ 1;
3696 x_rectangle (XFRAME (frame
), XFRAME (frame
)->display
.x
->reverse_gc
,
3697 left
, top
, n_chars
, n_lines
);
3703 /* Draw lines around the text region beginning at the character position
3704 TOP_X, TOP_Y and ending at BOTTOM_X and BOTTOM_Y. GC specifies the
3705 pixel and line characteristics. */
3707 #define line_len(line) (FRAME_CURRENT_GLYPHS (f)->used[(line)])
3710 outline_region (f
, gc
, top_x
, top_y
, bottom_x
, bottom_y
)
3711 register struct frame
*f
;
3713 int top_x
, top_y
, bottom_x
, bottom_y
;
3715 register int ibw
= f
->display
.x
->internal_border_width
;
3716 register int font_w
= FONT_WIDTH (f
->display
.x
->font
);
3717 register int font_h
= f
->display
.x
->line_height
;
3719 int x
= line_len (y
);
3720 XPoint
*pixel_points
3721 = (XPoint
*) alloca (((bottom_y
- top_y
+ 2) * 4) * sizeof (XPoint
));
3722 register XPoint
*this_point
= pixel_points
;
3724 /* Do the horizontal top line/lines */
3727 this_point
->x
= ibw
;
3728 this_point
->y
= ibw
+ (font_h
* top_y
);
3731 this_point
->x
= ibw
+ (font_w
/ 2); /* Half-size for newline chars. */
3733 this_point
->x
= ibw
+ (font_w
* x
);
3734 this_point
->y
= (this_point
- 1)->y
;
3738 this_point
->x
= ibw
;
3739 this_point
->y
= ibw
+ (font_h
* (top_y
+ 1));
3741 this_point
->x
= ibw
+ (font_w
* top_x
);
3742 this_point
->y
= (this_point
- 1)->y
;
3744 this_point
->x
= (this_point
- 1)->x
;
3745 this_point
->y
= ibw
+ (font_h
* top_y
);
3747 this_point
->x
= ibw
+ (font_w
* x
);
3748 this_point
->y
= (this_point
- 1)->y
;
3751 /* Now do the right side. */
3752 while (y
< bottom_y
)
3753 { /* Right vertical edge */
3755 this_point
->x
= (this_point
- 1)->x
;
3756 this_point
->y
= ibw
+ (font_h
* (y
+ 1));
3759 y
++; /* Horizontal connection to next line */
3762 this_point
->x
= ibw
+ (font_w
/ 2);
3764 this_point
->x
= ibw
+ (font_w
* x
);
3766 this_point
->y
= (this_point
- 1)->y
;
3769 /* Now do the bottom and connect to the top left point. */
3770 this_point
->x
= ibw
+ (font_w
* (bottom_x
+ 1));
3773 this_point
->x
= (this_point
- 1)->x
;
3774 this_point
->y
= ibw
+ (font_h
* (bottom_y
+ 1));
3776 this_point
->x
= ibw
;
3777 this_point
->y
= (this_point
- 1)->y
;
3779 this_point
->x
= pixel_points
->x
;
3780 this_point
->y
= pixel_points
->y
;
3782 XDrawLines (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3784 (this_point
- pixel_points
+ 1), CoordModeOrigin
);
3787 DEFUN ("x-contour-region", Fx_contour_region
, Sx_contour_region
, 1, 1, 0,
3788 "Highlight the region between point and the character under the mouse\n\
3791 register Lisp_Object event
;
3793 register int x0
, y0
, x1
, y1
;
3794 register struct frame
*f
= selected_frame
;
3795 register int p1
, p2
;
3797 CHECK_CONS (event
, 0);
3800 x0
= XINT (Fcar (Fcar (event
)));
3801 y0
= XINT (Fcar (Fcdr (Fcar (event
))));
3803 /* If the mouse is past the end of the line, don't that area. */
3804 /* ReWrite this... */
3809 if (y1
> y0
) /* point below mouse */
3810 outline_region (f
, f
->display
.x
->cursor_gc
,
3812 else if (y1
< y0
) /* point above mouse */
3813 outline_region (f
, f
->display
.x
->cursor_gc
,
3815 else /* same line: draw horizontal rectangle */
3818 x_rectangle (f
, f
->display
.x
->cursor_gc
,
3819 x0
, y0
, (x1
- x0
+ 1), 1);
3821 x_rectangle (f
, f
->display
.x
->cursor_gc
,
3822 x1
, y1
, (x0
- x1
+ 1), 1);
3825 XFlush (FRAME_X_DISPLAY (f
));
3831 DEFUN ("x-uncontour-region", Fx_uncontour_region
, Sx_uncontour_region
, 1, 1, 0,
3832 "Erase any highlighting of the region between point and the character\n\
3833 at X, Y on the selected frame.")
3835 register Lisp_Object event
;
3837 register int x0
, y0
, x1
, y1
;
3838 register struct frame
*f
= selected_frame
;
3841 x0
= XINT (Fcar (Fcar (event
)));
3842 y0
= XINT (Fcar (Fcdr (Fcar (event
))));
3846 if (y1
> y0
) /* point below mouse */
3847 outline_region (f
, f
->display
.x
->reverse_gc
,
3849 else if (y1
< y0
) /* point above mouse */
3850 outline_region (f
, f
->display
.x
->reverse_gc
,
3852 else /* same line: draw horizontal rectangle */
3855 x_rectangle (f
, f
->display
.x
->reverse_gc
,
3856 x0
, y0
, (x1
- x0
+ 1), 1);
3858 x_rectangle (f
, f
->display
.x
->reverse_gc
,
3859 x1
, y1
, (x0
- x1
+ 1), 1);
3867 int contour_begin_x
, contour_begin_y
;
3868 int contour_end_x
, contour_end_y
;
3869 int contour_npoints
;
3871 /* Clip the top part of the contour lines down (and including) line Y_POS.
3872 If X_POS is in the middle (rather than at the end) of the line, drop
3873 down a line at that character. */
3876 clip_contour_top (y_pos
, x_pos
)
3878 register XPoint
*begin
= contour_lines
[y_pos
].top_left
;
3879 register XPoint
*end
;
3880 register int npoints
;
3881 register struct display_line
*line
= selected_frame
->phys_lines
[y_pos
+ 1];
3883 if (x_pos
>= line
->len
- 1) /* Draw one, straight horizontal line. */
3885 end
= contour_lines
[y_pos
].top_right
;
3886 npoints
= (end
- begin
+ 1);
3887 XDrawLines (x_current_display
, contour_window
,
3888 contour_erase_gc
, begin_erase
, npoints
, CoordModeOrigin
);
3890 bcopy (end
, begin
+ 1, contour_last_point
- end
+ 1);
3891 contour_last_point
-= (npoints
- 2);
3892 XDrawLines (x_current_display
, contour_window
,
3893 contour_erase_gc
, begin
, 2, CoordModeOrigin
);
3894 XFlush (x_current_display
);
3896 /* Now, update contour_lines structure. */
3901 register XPoint
*p
= begin
+ 1;
3902 end
= contour_lines
[y_pos
].bottom_right
;
3903 npoints
= (end
- begin
+ 1);
3904 XDrawLines (x_current_display
, contour_window
,
3905 contour_erase_gc
, begin_erase
, npoints
, CoordModeOrigin
);
3908 p
->x
= ibw
+ (font_w
* (x_pos
+ 1));
3910 p
->y
= begin
->y
+ font_h
;
3912 bcopy (end
, begin
+ 3, contour_last_point
- end
+ 1);
3913 contour_last_point
-= (npoints
- 5);
3914 XDrawLines (x_current_display
, contour_window
,
3915 contour_erase_gc
, begin
, 4, CoordModeOrigin
);
3916 XFlush (x_current_display
);
3918 /* Now, update contour_lines structure. */
3922 /* Erase the top horizontal lines of the contour, and then extend
3923 the contour upwards. */
3926 extend_contour_top (line
)
3931 clip_contour_bottom (x_pos
, y_pos
)
3937 extend_contour_bottom (x_pos
, y_pos
)
3941 DEFUN ("x-select-region", Fx_select_region
, Sx_select_region
, 1, 1, "e",
3946 register struct frame
*f
= selected_frame
;
3947 register int point_x
= f
->cursor_x
;
3948 register int point_y
= f
->cursor_y
;
3949 register int mouse_below_point
;
3950 register Lisp_Object obj
;
3951 register int x_contour_x
, x_contour_y
;
3953 x_contour_x
= x_mouse_x
;
3954 x_contour_y
= x_mouse_y
;
3955 if (x_contour_y
> point_y
|| (x_contour_y
== point_y
3956 && x_contour_x
> point_x
))
3958 mouse_below_point
= 1;
3959 outline_region (f
, f
->display
.x
->cursor_gc
, point_x
, point_y
,
3960 x_contour_x
, x_contour_y
);
3964 mouse_below_point
= 0;
3965 outline_region (f
, f
->display
.x
->cursor_gc
, x_contour_x
, x_contour_y
,
3971 obj
= read_char (-1, 0, 0, Qnil
, 0);
3975 if (mouse_below_point
)
3977 if (x_mouse_y
<= point_y
) /* Flipped. */
3979 mouse_below_point
= 0;
3981 outline_region (f
, f
->display
.x
->reverse_gc
, point_x
, point_y
,
3982 x_contour_x
, x_contour_y
);
3983 outline_region (f
, f
->display
.x
->cursor_gc
, x_mouse_x
, x_mouse_y
,
3986 else if (x_mouse_y
< x_contour_y
) /* Bottom clipped. */
3988 clip_contour_bottom (x_mouse_y
);
3990 else if (x_mouse_y
> x_contour_y
) /* Bottom extended. */
3992 extend_bottom_contour (x_mouse_y
);
3995 x_contour_x
= x_mouse_x
;
3996 x_contour_y
= x_mouse_y
;
3998 else /* mouse above or same line as point */
4000 if (x_mouse_y
>= point_y
) /* Flipped. */
4002 mouse_below_point
= 1;
4004 outline_region (f
, f
->display
.x
->reverse_gc
,
4005 x_contour_x
, x_contour_y
, point_x
, point_y
);
4006 outline_region (f
, f
->display
.x
->cursor_gc
, point_x
, point_y
,
4007 x_mouse_x
, x_mouse_y
);
4009 else if (x_mouse_y
> x_contour_y
) /* Top clipped. */
4011 clip_contour_top (x_mouse_y
);
4013 else if (x_mouse_y
< x_contour_y
) /* Top extended. */
4015 extend_contour_top (x_mouse_y
);
4020 unread_command_event
= obj
;
4021 if (mouse_below_point
)
4023 contour_begin_x
= point_x
;
4024 contour_begin_y
= point_y
;
4025 contour_end_x
= x_contour_x
;
4026 contour_end_y
= x_contour_y
;
4030 contour_begin_x
= x_contour_x
;
4031 contour_begin_y
= x_contour_y
;
4032 contour_end_x
= point_x
;
4033 contour_end_y
= point_y
;
4038 DEFUN ("x-horizontal-line", Fx_horizontal_line
, Sx_horizontal_line
, 1, 1, "e",
4043 register Lisp_Object obj
;
4044 struct frame
*f
= selected_frame
;
4045 register struct window
*w
= XWINDOW (selected_window
);
4046 register GC line_gc
= f
->display
.x
->cursor_gc
;
4047 register GC erase_gc
= f
->display
.x
->reverse_gc
;
4049 char dash_list
[] = {6, 4, 6, 4};
4051 XGCValues gc_values
;
4053 register int previous_y
;
4054 register int line
= (x_mouse_y
+ 1) * f
->display
.x
->line_height
4055 + f
->display
.x
->internal_border_width
;
4056 register int left
= f
->display
.x
->internal_border_width
4058 * FONT_WIDTH (f
->display
.x
->font
));
4059 register int right
= left
+ (w
->width
4060 * FONT_WIDTH (f
->display
.x
->font
))
4061 - f
->display
.x
->internal_border_width
;
4065 gc_values
.foreground
= f
->display
.x
->cursor_pixel
;
4066 gc_values
.background
= f
->display
.x
->background_pixel
;
4067 gc_values
.line_width
= 1;
4068 gc_values
.line_style
= LineOnOffDash
;
4069 gc_values
.cap_style
= CapRound
;
4070 gc_values
.join_style
= JoinRound
;
4072 line_gc
= XCreateGC (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
4073 GCLineStyle
| GCJoinStyle
| GCCapStyle
4074 | GCLineWidth
| GCForeground
| GCBackground
,
4076 XSetDashes (FRAME_X_DISPLAY (f
), line_gc
, 0, dash_list
, dashes
);
4077 gc_values
.foreground
= f
->display
.x
->background_pixel
;
4078 gc_values
.background
= f
->display
.x
->foreground_pixel
;
4079 erase_gc
= XCreateGC (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
4080 GCLineStyle
| GCJoinStyle
| GCCapStyle
4081 | GCLineWidth
| GCForeground
| GCBackground
,
4083 XSetDashes (FRAME_X_DISPLAY (f
), erase_gc
, 0, dash_list
, dashes
);
4089 if (x_mouse_y
>= XINT (w
->top
)
4090 && x_mouse_y
< XINT (w
->top
) + XINT (w
->height
) - 1)
4092 previous_y
= x_mouse_y
;
4093 line
= (x_mouse_y
+ 1) * f
->display
.x
->line_height
4094 + f
->display
.x
->internal_border_width
;
4095 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
4096 line_gc
, left
, line
, right
, line
);
4098 XFlush (FRAME_X_DISPLAY (f
));
4103 obj
= read_char (-1, 0, 0, Qnil
, 0);
4105 || (! EQ (Fcar (Fcdr (Fcdr (obj
))),
4106 Qvertical_scroll_bar
))
4110 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
4111 erase_gc
, left
, line
, right
, line
);
4113 unread_command_event
= obj
;
4115 XFreeGC (FRAME_X_DISPLAY (f
), line_gc
);
4116 XFreeGC (FRAME_X_DISPLAY (f
), erase_gc
);
4121 while (x_mouse_y
== previous_y
);
4124 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
4125 erase_gc
, left
, line
, right
, line
);
4132 /* These keep track of the rectangle following the pointer. */
4133 int mouse_track_top
, mouse_track_left
, mouse_track_width
;
4135 /* Offset in buffer of character under the pointer, or 0. */
4136 int mouse_buffer_offset
;
4138 DEFUN ("x-track-pointer", Fx_track_pointer
, Sx_track_pointer
, 0, 0, 0,
4139 "Track the pointer.")
4142 static Cursor current_pointer_shape
;
4143 FRAME_PTR f
= x_mouse_frame
;
4146 if (EQ (Vmouse_frame_part
, Qtext_part
)
4147 && (current_pointer_shape
!= f
->display
.x
->nontext_cursor
))
4152 current_pointer_shape
= f
->display
.x
->nontext_cursor
;
4153 XDefineCursor (FRAME_X_DISPLAY (f
),
4155 current_pointer_shape
);
4157 buf
= XBUFFER (XWINDOW (Vmouse_window
)->buffer
);
4158 c
= *(BUF_CHAR_ADDRESS (buf
, mouse_buffer_offset
));
4160 else if (EQ (Vmouse_frame_part
, Qmodeline_part
)
4161 && (current_pointer_shape
!= f
->display
.x
->modeline_cursor
))
4163 current_pointer_shape
= f
->display
.x
->modeline_cursor
;
4164 XDefineCursor (FRAME_X_DISPLAY (f
),
4166 current_pointer_shape
);
4169 XFlush (FRAME_X_DISPLAY (f
));
4175 DEFUN ("x-track-pointer", Fx_track_pointer
, Sx_track_pointer
, 1, 1, "e",
4176 "Draw rectangle around character under mouse pointer, if there is one.")
4180 struct window
*w
= XWINDOW (Vmouse_window
);
4181 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
4182 struct buffer
*b
= XBUFFER (w
->buffer
);
4185 if (! EQ (Vmouse_window
, selected_window
))
4188 if (EQ (event
, Qnil
))
4192 x_read_mouse_position (selected_frame
, &x
, &y
);
4196 mouse_track_width
= 0;
4197 mouse_track_left
= mouse_track_top
= -1;
4201 if ((x_mouse_x
!= mouse_track_left
4202 && (x_mouse_x
< mouse_track_left
4203 || x_mouse_x
> (mouse_track_left
+ mouse_track_width
)))
4204 || x_mouse_y
!= mouse_track_top
)
4206 int hp
= 0; /* Horizontal position */
4207 int len
= FRAME_CURRENT_GLYPHS (f
)->used
[x_mouse_y
];
4208 int p
= FRAME_CURRENT_GLYPHS (f
)->bufp
[x_mouse_y
];
4209 int tab_width
= XINT (b
->tab_width
);
4210 int ctl_arrow_p
= !NILP (b
->ctl_arrow
);
4212 int mode_line_vpos
= XFASTINT (w
->height
) + XFASTINT (w
->top
) - 1;
4213 int in_mode_line
= 0;
4215 if (! FRAME_CURRENT_GLYPHS (f
)->enable
[x_mouse_y
])
4218 /* Erase previous rectangle. */
4219 if (mouse_track_width
)
4221 x_rectangle (f
, f
->display
.x
->reverse_gc
,
4222 mouse_track_left
, mouse_track_top
,
4223 mouse_track_width
, 1);
4225 if ((mouse_track_left
== f
->phys_cursor_x
4226 || mouse_track_left
== f
->phys_cursor_x
- 1)
4227 && mouse_track_top
== f
->phys_cursor_y
)
4229 x_display_cursor (f
, 1);
4233 mouse_track_left
= x_mouse_x
;
4234 mouse_track_top
= x_mouse_y
;
4235 mouse_track_width
= 0;
4237 if (mouse_track_left
> len
) /* Past the end of line. */
4240 if (mouse_track_top
== mode_line_vpos
)
4246 if (tab_width
<= 0 || tab_width
> 20) tab_width
= 8;
4250 if (len
== f
->width
&& hp
== len
- 1 && c
!= '\n')
4256 mouse_track_width
= tab_width
- (hp
% tab_width
);
4258 hp
+= mouse_track_width
;
4261 mouse_track_left
= hp
- mouse_track_width
;
4267 mouse_track_width
= -1;
4271 if (ctl_arrow_p
&& (c
< 040 || c
== 0177))
4276 mouse_track_width
= 2;
4281 mouse_track_left
= hp
- mouse_track_width
;
4287 mouse_track_width
= 1;
4294 while (hp
<= x_mouse_x
);
4297 if (mouse_track_width
) /* Over text; use text pointer shape. */
4299 XDefineCursor (FRAME_X_DISPLAY (f
),
4301 f
->display
.x
->text_cursor
);
4302 x_rectangle (f
, f
->display
.x
->cursor_gc
,
4303 mouse_track_left
, mouse_track_top
,
4304 mouse_track_width
, 1);
4306 else if (in_mode_line
)
4307 XDefineCursor (FRAME_X_DISPLAY (f
),
4309 f
->display
.x
->modeline_cursor
);
4311 XDefineCursor (FRAME_X_DISPLAY (f
),
4313 f
->display
.x
->nontext_cursor
);
4316 XFlush (FRAME_X_DISPLAY (f
));
4319 obj
= read_char (-1, 0, 0, Qnil
, 0);
4322 while (CONSP (obj
) /* Mouse event */
4323 && EQ (Fcar (Fcdr (Fcdr (obj
))), Qnil
) /* Not scroll bar */
4324 && EQ (Vmouse_depressed
, Qnil
) /* Only motion events */
4325 && EQ (Vmouse_window
, selected_window
) /* In this window */
4328 unread_command_event
= obj
;
4330 if (mouse_track_width
)
4332 x_rectangle (f
, f
->display
.x
->reverse_gc
,
4333 mouse_track_left
, mouse_track_top
,
4334 mouse_track_width
, 1);
4335 mouse_track_width
= 0;
4336 if ((mouse_track_left
== f
->phys_cursor_x
4337 || mouse_track_left
- 1 == f
->phys_cursor_x
)
4338 && mouse_track_top
== f
->phys_cursor_y
)
4340 x_display_cursor (f
, 1);
4343 XDefineCursor (FRAME_X_DISPLAY (f
),
4345 f
->display
.x
->nontext_cursor
);
4346 XFlush (FRAME_X_DISPLAY (f
));
4356 /* Draw a pixmap specified by IMAGE_DATA of dimensions WIDTH and HEIGHT
4357 on the frame F at position X, Y. */
4359 x_draw_pixmap (f
, x
, y
, image_data
, width
, height
)
4361 int x
, y
, width
, height
;
4366 image
= XCreateBitmapFromData (FRAME_X_DISPLAY (f
),
4367 FRAME_X_WINDOW (f
), image_data
,
4369 XCopyPlane (FRAME_X_DISPLAY (f
), image
, FRAME_X_WINDOW (f
),
4370 f
->display
.x
->normal_gc
, 0, 0, width
, height
, x
, y
);
4374 #if 0 /* I'm told these functions are superfluous
4375 given the ability to bind function keys. */
4378 DEFUN ("x-rebind-key", Fx_rebind_key
, Sx_rebind_key
, 3, 3, 0,
4379 "Rebind X keysym KEYSYM, with MODIFIERS, to generate NEWSTRING.\n\
4380 KEYSYM is a string which conforms to the X keysym definitions found\n\
4381 in X11/keysymdef.h, sans the initial XK_. MODIFIERS is nil or a\n\
4382 list of strings specifying modifier keys such as Control_L, which must\n\
4383 also be depressed for NEWSTRING to appear.")
4384 (x_keysym
, modifiers
, newstring
)
4385 register Lisp_Object x_keysym
;
4386 register Lisp_Object modifiers
;
4387 register Lisp_Object newstring
;
4390 register KeySym keysym
;
4391 KeySym modifier_list
[16];
4394 CHECK_STRING (x_keysym
, 1);
4395 CHECK_STRING (newstring
, 3);
4397 keysym
= XStringToKeysym ((char *) XSTRING (x_keysym
)->data
);
4398 if (keysym
== NoSymbol
)
4399 error ("Keysym does not exist");
4401 if (NILP (modifiers
))
4402 XRebindKeysym (x_current_display
, keysym
, modifier_list
, 0,
4403 XSTRING (newstring
)->data
, XSTRING (newstring
)->size
);
4406 register Lisp_Object rest
, mod
;
4409 for (rest
= modifiers
; !NILP (rest
); rest
= Fcdr (rest
))
4412 error ("Can't have more than 16 modifiers");
4415 CHECK_STRING (mod
, 3);
4416 modifier_list
[i
] = XStringToKeysym ((char *) XSTRING (mod
)->data
);
4418 if (modifier_list
[i
] == NoSymbol
4419 || !(IsModifierKey (modifier_list
[i
])
4420 || ((unsigned)(modifier_list
[i
]) == XK_Mode_switch
)
4421 || ((unsigned)(modifier_list
[i
]) == XK_Num_Lock
)))
4423 if (modifier_list
[i
] == NoSymbol
4424 || !IsModifierKey (modifier_list
[i
]))
4426 error ("Element is not a modifier keysym");
4430 XRebindKeysym (x_current_display
, keysym
, modifier_list
, i
,
4431 XSTRING (newstring
)->data
, XSTRING (newstring
)->size
);
4437 DEFUN ("x-rebind-keys", Fx_rebind_keys
, Sx_rebind_keys
, 2, 2, 0,
4438 "Rebind KEYCODE to list of strings STRINGS.\n\
4439 STRINGS should be a list of 16 elements, one for each shift combination.\n\
4440 nil as element means don't change.\n\
4441 See the documentation of `x-rebind-key' for more information.")
4443 register Lisp_Object keycode
;
4444 register Lisp_Object strings
;
4446 register Lisp_Object item
;
4447 register unsigned char *rawstring
;
4448 KeySym rawkey
, modifier
[1];
4450 register unsigned i
;
4453 CHECK_NUMBER (keycode
, 1);
4454 CHECK_CONS (strings
, 2);
4455 rawkey
= (KeySym
) ((unsigned) (XINT (keycode
))) & 255;
4456 for (i
= 0; i
<= 15; strings
= Fcdr (strings
), i
++)
4458 item
= Fcar (strings
);
4461 CHECK_STRING (item
, 2);
4462 strsize
= XSTRING (item
)->size
;
4463 rawstring
= (unsigned char *) xmalloc (strsize
);
4464 bcopy (XSTRING (item
)->data
, rawstring
, strsize
);
4465 modifier
[1] = 1 << i
;
4466 XRebindKeysym (x_current_display
, rawkey
, modifier
, 1,
4467 rawstring
, strsize
);
4472 #endif /* HAVE_X11 */
4475 #ifndef HAVE_XSCREENNUMBEROFSCREEN
4477 XScreenNumberOfScreen (scr
)
4478 register Screen
*scr
;
4480 register Display
*dpy
;
4481 register Screen
*dpyscr
;
4485 dpyscr
= dpy
->screens
;
4487 for (i
= 0; i
< dpy
->nscreens
; i
++, dpyscr
++)
4493 #endif /* not HAVE_XSCREENNUMBEROFSCREEN */
4496 select_visual (dpy
, screen
, depth
)
4499 unsigned int *depth
;
4502 XVisualInfo
*vinfo
, vinfo_template
;
4505 v
= DefaultVisualOfScreen (screen
);
4508 vinfo_template
.visualid
= XVisualIDFromVisual (v
);
4510 vinfo_template
.visualid
= v
->visualid
;
4513 vinfo_template
.screen
= XScreenNumberOfScreen (screen
);
4515 vinfo
= XGetVisualInfo (dpy
,
4516 VisualIDMask
| VisualScreenMask
, &vinfo_template
,
4519 fatal ("Can't get proper X visual info");
4521 if ((1 << vinfo
->depth
) == vinfo
->colormap_size
)
4522 *depth
= vinfo
->depth
;
4526 int n
= vinfo
->colormap_size
- 1;
4535 XFree ((char *) vinfo
);
4539 /* Return the X display structure for the display named NAME.
4540 Open a new connection if necessary. */
4542 struct x_display_info
*
4543 x_display_info_for_name (name
)
4547 struct x_display_info
*dpyinfo
;
4549 CHECK_STRING (name
, 0);
4551 for (dpyinfo
= x_display_list
, names
= x_display_name_list
;
4553 dpyinfo
= dpyinfo
->next
, names
= XCONS (names
)->cdr
)
4556 tem
= Fstring_equal (XCONS (XCONS (names
)->car
)->car
, name
);
4561 validate_x_resource_name ();
4563 dpyinfo
= x_term_init (name
, (unsigned char *)0,
4564 XSTRING (Vx_resource_name
)->data
);
4567 error ("X server %s not responding", XSTRING (name
)->data
);
4570 XSETFASTINT (Vwindow_system_version
, 11);
4575 DEFUN ("x-open-connection", Fx_open_connection
, Sx_open_connection
,
4576 1, 3, 0, "Open a connection to an X server.\n\
4577 DISPLAY is the name of the display to connect to.\n\
4578 Optional second arg XRM-STRING is a string of resources in xrdb format.\n\
4579 If the optional third arg MUST-SUCCEED is non-nil,\n\
4580 terminate Emacs if we can't open the connection.")
4581 (display
, xrm_string
, must_succeed
)
4582 Lisp_Object display
, xrm_string
, must_succeed
;
4584 unsigned int n_planes
;
4585 unsigned char *xrm_option
;
4586 struct x_display_info
*dpyinfo
;
4588 CHECK_STRING (display
, 0);
4589 if (! NILP (xrm_string
))
4590 CHECK_STRING (xrm_string
, 1);
4592 if (! NILP (xrm_string
))
4593 xrm_option
= (unsigned char *) XSTRING (xrm_string
)->data
;
4595 xrm_option
= (unsigned char *) 0;
4597 validate_x_resource_name ();
4599 /* This is what opens the connection and sets x_current_display.
4600 This also initializes many symbols, such as those used for input. */
4601 dpyinfo
= x_term_init (display
, xrm_option
,
4602 XSTRING (Vx_resource_name
)->data
);
4606 if (!NILP (must_succeed
))
4607 fatal ("X server %s not responding.\n\
4608 Check the DISPLAY environment variable or use \"-d\"\n",
4609 XSTRING (display
)->data
);
4611 error ("X server %s not responding", XSTRING (display
)->data
);
4616 XSETFASTINT (Vwindow_system_version
, 11);
4620 DEFUN ("x-close-connection", Fx_close_connection
,
4621 Sx_close_connection
, 1, 1, 0,
4622 "Close the connection to DISPLAY's X server.\n\
4623 For DISPLAY, specify either a frame or a display name (a string).\n\
4624 If DISPLAY is nil, that stands for the selected frame's display.")
4626 Lisp_Object display
;
4628 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
4629 struct x_display_info
*tail
;
4632 if (dpyinfo
->reference_count
> 0)
4633 error ("Display still has frames on it");
4636 /* Free the fonts in the font table. */
4637 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
4639 if (dpyinfo
->font_table
[i
].name
)
4640 free (dpyinfo
->font_table
[i
].name
);
4641 /* Don't free the full_name string;
4642 it is always shared with something else. */
4643 XFreeFont (dpyinfo
->display
, dpyinfo
->font_table
[i
].font
);
4645 x_destroy_all_bitmaps (dpyinfo
);
4646 XSetCloseDownMode (dpyinfo
->display
, DestroyAll
);
4648 #ifdef USE_X_TOOLKIT
4649 XtCloseDisplay (dpyinfo
->display
);
4651 XCloseDisplay (dpyinfo
->display
);
4654 x_delete_display (dpyinfo
);
4660 DEFUN ("x-display-list", Fx_display_list
, Sx_display_list
, 0, 0, 0,
4661 "Return the list of display names that Emacs has connections to.")
4664 Lisp_Object tail
, result
;
4667 for (tail
= x_display_name_list
; ! NILP (tail
); tail
= XCONS (tail
)->cdr
)
4668 result
= Fcons (XCONS (XCONS (tail
)->car
)->car
, result
);
4673 DEFUN ("x-synchronize", Fx_synchronize
, Sx_synchronize
, 1, 2, 0,
4674 "If ON is non-nil, report X errors as soon as the erring request is made.\n\
4675 If ON is nil, allow buffering of requests.\n\
4676 Turning on synchronization prohibits the Xlib routines from buffering\n\
4677 requests and seriously degrades performance, but makes debugging much\n\
4679 The optional second argument DISPLAY specifies which display to act on.\n\
4680 DISPLAY should be either a frame or a display name (a string).\n\
4681 If DISPLAY is omitted or nil, that stands for the selected frame's display.")
4683 Lisp_Object display
, on
;
4685 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
4687 XSynchronize (dpyinfo
->display
, !EQ (on
, Qnil
));
4692 /* Wait for responses to all X commands issued so far for frame F. */
4699 XSync (FRAME_X_DISPLAY (f
), False
);
4705 /* This is zero if not using X windows. */
4708 /* The section below is built by the lisp expression at the top of the file,
4709 just above where these variables are declared. */
4710 /*&&& init symbols here &&&*/
4711 Qauto_raise
= intern ("auto-raise");
4712 staticpro (&Qauto_raise
);
4713 Qauto_lower
= intern ("auto-lower");
4714 staticpro (&Qauto_lower
);
4715 Qbackground_color
= intern ("background-color");
4716 staticpro (&Qbackground_color
);
4717 Qbar
= intern ("bar");
4719 Qborder_color
= intern ("border-color");
4720 staticpro (&Qborder_color
);
4721 Qborder_width
= intern ("border-width");
4722 staticpro (&Qborder_width
);
4723 Qbox
= intern ("box");
4725 Qcursor_color
= intern ("cursor-color");
4726 staticpro (&Qcursor_color
);
4727 Qcursor_type
= intern ("cursor-type");
4728 staticpro (&Qcursor_type
);
4729 Qfont
= intern ("font");
4731 Qforeground_color
= intern ("foreground-color");
4732 staticpro (&Qforeground_color
);
4733 Qgeometry
= intern ("geometry");
4734 staticpro (&Qgeometry
);
4735 Qicon_left
= intern ("icon-left");
4736 staticpro (&Qicon_left
);
4737 Qicon_top
= intern ("icon-top");
4738 staticpro (&Qicon_top
);
4739 Qicon_type
= intern ("icon-type");
4740 staticpro (&Qicon_type
);
4741 Qinternal_border_width
= intern ("internal-border-width");
4742 staticpro (&Qinternal_border_width
);
4743 Qleft
= intern ("left");
4745 Qmouse_color
= intern ("mouse-color");
4746 staticpro (&Qmouse_color
);
4747 Qnone
= intern ("none");
4749 Qparent_id
= intern ("parent-id");
4750 staticpro (&Qparent_id
);
4751 Qscroll_bar_width
= intern ("scroll-bar-width");
4752 staticpro (&Qscroll_bar_width
);
4753 Qsuppress_icon
= intern ("suppress-icon");
4754 staticpro (&Qsuppress_icon
);
4755 Qtop
= intern ("top");
4757 Qundefined_color
= intern ("undefined-color");
4758 staticpro (&Qundefined_color
);
4759 Qvertical_scroll_bars
= intern ("vertical-scroll-bars");
4760 staticpro (&Qvertical_scroll_bars
);
4761 Qvisibility
= intern ("visibility");
4762 staticpro (&Qvisibility
);
4763 Qwindow_id
= intern ("window-id");
4764 staticpro (&Qwindow_id
);
4765 Qx_frame_parameter
= intern ("x-frame-parameter");
4766 staticpro (&Qx_frame_parameter
);
4767 Qx_resource_name
= intern ("x-resource-name");
4768 staticpro (&Qx_resource_name
);
4769 Quser_position
= intern ("user-position");
4770 staticpro (&Quser_position
);
4771 Quser_size
= intern ("user-size");
4772 staticpro (&Quser_size
);
4773 Qdisplay
= intern ("display");
4774 staticpro (&Qdisplay
);
4775 /* This is the end of symbol initialization. */
4777 Fput (Qundefined_color
, Qerror_conditions
,
4778 Fcons (Qundefined_color
, Fcons (Qerror
, Qnil
)));
4779 Fput (Qundefined_color
, Qerror_message
,
4780 build_string ("Undefined color"));
4782 init_x_parm_symbols ();
4784 DEFVAR_LISP ("x-bitmap-file-path", &Vx_bitmap_file_path
,
4785 "List of directories to search for bitmap files for X.");
4786 Vx_bitmap_file_path
= Fcons (build_string (PATH_BITMAPS
), Qnil
);
4788 DEFVAR_LISP ("x-pointer-shape", &Vx_pointer_shape
,
4789 "The shape of the pointer when over text.\n\
4790 Changing the value does not affect existing frames\n\
4791 unless you set the mouse color.");
4792 Vx_pointer_shape
= Qnil
;
4794 DEFVAR_LISP ("x-resource-name", &Vx_resource_name
,
4795 "The name Emacs uses to look up X resources; for internal use only.\n\
4796 `x-get-resource' uses this as the first component of the instance name\n\
4797 when requesting resource values.\n\
4798 Emacs initially sets `x-resource-name' to the name under which Emacs\n\
4799 was invoked, or to the value specified with the `-name' or `-rn'\n\
4800 switches, if present.");
4801 Vx_resource_name
= Qnil
;
4803 #if 0 /* This doesn't really do anything. */
4804 DEFVAR_INT ("x-nontext-pointer-shape", &Vx_nontext_pointer_shape
,
4805 "The shape of the pointer when not over text.\n\
4806 This variable takes effect when you create a new frame\n\
4807 or when you set the mouse color.");
4809 Vx_nontext_pointer_shape
= Qnil
;
4811 #if 0 /* This doesn't really do anything. */
4812 DEFVAR_INT ("x-mode-pointer-shape", &Vx_mode_pointer_shape
,
4813 "The shape of the pointer when over the mode line.\n\
4814 This variable takes effect when you create a new frame\n\
4815 or when you set the mouse color.");
4817 Vx_mode_pointer_shape
= Qnil
;
4819 DEFVAR_INT ("x-sensitive-text-pointer-shape",
4820 &Vx_sensitive_text_pointer_shape
,
4821 "The shape of the pointer when over mouse-sensitive text.\n\
4822 This variable takes effect when you create a new frame\n\
4823 or when you set the mouse color.");
4824 Vx_sensitive_text_pointer_shape
= Qnil
;
4826 DEFVAR_LISP ("x-cursor-fore-pixel", &Vx_cursor_fore_pixel
,
4827 "A string indicating the foreground color of the cursor box.");
4828 Vx_cursor_fore_pixel
= Qnil
;
4830 DEFVAR_LISP ("x-no-window-manager", &Vx_no_window_manager
,
4831 "Non-nil if no X window manager is in use.");
4833 #ifdef USE_X_TOOLKIT
4834 Fprovide (intern ("x-toolkit"));
4837 defsubr (&Sx_get_resource
);
4839 defsubr (&Sx_draw_rectangle
);
4840 defsubr (&Sx_erase_rectangle
);
4841 defsubr (&Sx_contour_region
);
4842 defsubr (&Sx_uncontour_region
);
4844 defsubr (&Sx_list_fonts
);
4845 defsubr (&Sx_display_color_p
);
4846 defsubr (&Sx_display_grayscale_p
);
4847 defsubr (&Sx_color_defined_p
);
4848 defsubr (&Sx_color_values
);
4849 defsubr (&Sx_server_max_request_size
);
4850 defsubr (&Sx_server_vendor
);
4851 defsubr (&Sx_server_version
);
4852 defsubr (&Sx_display_pixel_width
);
4853 defsubr (&Sx_display_pixel_height
);
4854 defsubr (&Sx_display_mm_width
);
4855 defsubr (&Sx_display_mm_height
);
4856 defsubr (&Sx_display_screens
);
4857 defsubr (&Sx_display_planes
);
4858 defsubr (&Sx_display_color_cells
);
4859 defsubr (&Sx_display_visual_class
);
4860 defsubr (&Sx_display_backing_store
);
4861 defsubr (&Sx_display_save_under
);
4863 defsubr (&Sx_rebind_key
);
4864 defsubr (&Sx_rebind_keys
);
4865 defsubr (&Sx_track_pointer
);
4866 defsubr (&Sx_grab_pointer
);
4867 defsubr (&Sx_ungrab_pointer
);
4869 defsubr (&Sx_parse_geometry
);
4870 defsubr (&Sx_create_frame
);
4871 defsubr (&Sfocus_frame
);
4872 defsubr (&Sunfocus_frame
);
4874 defsubr (&Sx_horizontal_line
);
4876 defsubr (&Sx_open_connection
);
4877 defsubr (&Sx_close_connection
);
4878 defsubr (&Sx_display_list
);
4879 defsubr (&Sx_synchronize
);
4882 #endif /* HAVE_X_WINDOWS */