1 /* Functions for the X window system.
2 Copyright (C) 1989, 1992, 1993, 1994 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 /* The one and only application context associated with the connection
82 to the one and only X display that Emacs uses. */
83 XtAppContext Xt_app_con
;
85 /* The one and only application shell. Emacs screens are popup shells of this
89 extern void free_frame_menubar ();
90 #endif /* USE_X_TOOLKIT */
92 #define min(a,b) ((a) < (b) ? (a) : (b))
93 #define max(a,b) ((a) > (b) ? (a) : (b))
96 #define MAXREQUEST(dpy) (XMaxRequestSize (dpy))
98 #define MAXREQUEST(dpy) ((dpy)->max_request_size)
101 /* The name we're using in resource queries. */
102 Lisp_Object Vx_resource_name
;
104 /* Title name and application name for X stuff. */
105 extern char *x_id_name
;
107 /* The background and shape of the mouse pointer, and shape when not
108 over text or in the modeline. */
109 Lisp_Object Vx_pointer_shape
, Vx_nontext_pointer_shape
, Vx_mode_pointer_shape
;
110 /* The shape when over mouse-sensitive text. */
111 Lisp_Object Vx_sensitive_text_pointer_shape
;
113 /* Color of chars displayed in cursor box. */
114 Lisp_Object Vx_cursor_fore_pixel
;
116 /* Nonzero if using X. */
119 /* Non nil if no window manager is in use. */
120 Lisp_Object Vx_no_window_manager
;
122 /* Search path for bitmap files. */
123 Lisp_Object Vx_bitmap_file_path
;
125 /* Evaluate this expression to rebuild the section of syms_of_xfns
126 that initializes and staticpros the symbols declared below. Note
127 that Emacs 18 has a bug that keeps C-x C-e from being able to
128 evaluate this expression.
131 ;; Accumulate a list of the symbols we want to initialize from the
132 ;; declarations at the top of the file.
133 (goto-char (point-min))
134 (search-forward "/\*&&& symbols declared here &&&*\/\n")
136 (while (looking-at "Lisp_Object \\(Q[a-z_]+\\)")
138 (cons (buffer-substring (match-beginning 1) (match-end 1))
141 (setq symbol-list (nreverse symbol-list))
142 ;; Delete the section of syms_of_... where we initialize the symbols.
143 (search-forward "\n /\*&&& init symbols here &&&*\/\n")
144 (let ((start (point)))
145 (while (looking-at "^ Q")
147 (kill-region start (point)))
148 ;; Write a new symbol initialization section.
150 (insert (format " %s = intern (\"" (car symbol-list)))
151 (let ((start (point)))
152 (insert (substring (car symbol-list) 1))
153 (subst-char-in-region start (point) ?_ ?-))
154 (insert (format "\");\n staticpro (&%s);\n" (car symbol-list)))
155 (setq symbol-list (cdr symbol-list)))))
159 /*&&& symbols declared here &&&*/
160 Lisp_Object Qauto_raise
;
161 Lisp_Object Qauto_lower
;
162 Lisp_Object Qbackground_color
;
164 Lisp_Object Qborder_color
;
165 Lisp_Object Qborder_width
;
167 Lisp_Object Qcursor_color
;
168 Lisp_Object Qcursor_type
;
170 Lisp_Object Qforeground_color
;
171 Lisp_Object Qgeometry
;
172 Lisp_Object Qicon_left
;
173 Lisp_Object Qicon_top
;
174 Lisp_Object Qicon_type
;
175 Lisp_Object Qinternal_border_width
;
177 Lisp_Object Qmouse_color
;
179 Lisp_Object Qparent_id
;
180 Lisp_Object Qscroll_bar_width
;
181 Lisp_Object Qsuppress_icon
;
183 Lisp_Object Qundefined_color
;
184 Lisp_Object Qvertical_scroll_bars
;
185 Lisp_Object Qvisibility
;
186 Lisp_Object Qwindow_id
;
187 Lisp_Object Qx_frame_parameter
;
188 Lisp_Object Qx_resource_name
;
189 Lisp_Object Quser_position
;
190 Lisp_Object Quser_size
;
191 Lisp_Object Qdisplay
;
193 /* The below are defined in frame.c. */
194 extern Lisp_Object Qheight
, Qminibuffer
, Qname
, Qonly
, Qwidth
;
195 extern Lisp_Object Qunsplittable
, Qmenu_bar_lines
;
197 extern Lisp_Object Vwindow_system_version
;
200 /* Error if we are not connected to X. */
205 error ("X windows are not in use or not initialized");
208 /* Nonzero if using X for display. */
216 /* Extract a frame as a FRAME_PTR, defaulting to the selected frame
217 and checking validity for X. */
220 check_x_frame (frame
)
229 CHECK_LIVE_FRAME (frame
, 0);
233 error ("non-X frame used");
237 /* Let the user specify an X display with a frame.
238 nil stands for the selected frame--or, if that is not an X frame,
239 the first X display on the list. */
241 static struct x_display_info
*
242 check_x_display_info (frame
)
247 if (FRAME_X_P (selected_frame
))
248 return FRAME_X_DISPLAY_INFO (selected_frame
);
249 else if (x_display_list
!= 0)
250 return x_display_list
;
252 error ("X windows are not in use or not initialized");
254 else if (STRINGP (frame
))
255 return x_display_info_for_name (frame
);
260 CHECK_LIVE_FRAME (frame
, 0);
263 error ("non-X frame used");
264 return FRAME_X_DISPLAY_INFO (f
);
268 /* Return the Emacs frame-object corresponding to an X window.
269 It could be the frame's main window or an icon window. */
271 /* This function can be called during GC, so use XGCTYPE. */
274 x_window_to_frame (wdesc
)
277 Lisp_Object tail
, frame
;
280 for (tail
= Vframe_list
; XGCTYPE (tail
) == Lisp_Cons
;
281 tail
= XCONS (tail
)->cdr
)
283 frame
= XCONS (tail
)->car
;
284 if (XGCTYPE (frame
) != Lisp_Frame
)
288 if (f
->display
.nothing
== 1)
290 if ((f
->display
.x
->edit_widget
291 && XtWindow (f
->display
.x
->edit_widget
) == wdesc
)
292 || f
->display
.x
->icon_desc
== wdesc
)
294 #else /* not USE_X_TOOLKIT */
295 if (FRAME_X_WINDOW (f
) == wdesc
296 || f
->display
.x
->icon_desc
== wdesc
)
298 #endif /* not USE_X_TOOLKIT */
304 /* Like x_window_to_frame but also compares the window with the widget's
308 x_any_window_to_frame (wdesc
)
311 Lisp_Object tail
, frame
;
315 for (tail
= Vframe_list
; XGCTYPE (tail
) == Lisp_Cons
;
316 tail
= XCONS (tail
)->cdr
)
318 frame
= XCONS (tail
)->car
;
319 if (XGCTYPE (frame
) != Lisp_Frame
)
322 if (f
->display
.nothing
== 1)
325 /* This frame matches if the window is any of its widgets. */
326 if (wdesc
== XtWindow (x
->widget
)
327 || wdesc
== XtWindow (x
->column_widget
)
328 || wdesc
== XtWindow (x
->edit_widget
))
330 /* Match if the window is this frame's menubar. */
331 if (lw_window_is_in_menubar (wdesc
, x
->menubar_widget
))
337 /* Return the frame whose principal (outermost) window is WDESC.
338 If WDESC is some other (smaller) window, we return 0. */
341 x_top_window_to_frame (wdesc
)
344 Lisp_Object tail
, frame
;
348 for (tail
= Vframe_list
; XGCTYPE (tail
) == Lisp_Cons
;
349 tail
= XCONS (tail
)->cdr
)
351 frame
= XCONS (tail
)->car
;
352 if (XGCTYPE (frame
) != Lisp_Frame
)
355 if (f
->display
.nothing
== 1)
358 /* This frame matches if the window is its topmost widget. */
359 if (wdesc
== XtWindow (x
->widget
))
361 /* Match if the window is this frame's menubar. */
362 if (x
->menubar_widget
363 && wdesc
== XtWindow (x
->menubar_widget
))
368 #endif /* USE_X_TOOLKIT */
372 /* Code to deal with bitmaps. Bitmaps are referenced by their bitmap
373 id, which is just an int that this section returns. Bitmaps are
374 reference counted so they can be shared among frames.
376 Bitmap indices are guaranteed to be > 0, so a negative number can
377 be used to indicate no bitmap.
379 If you use x_create_bitmap_from_data, then you must keep track of
380 the bitmaps yourself. That is, creating a bitmap from the same
381 data more than once will not be caught. */
384 /* Structure recording X pixmap and reference count.
385 If REFCOUNT is 0 then this record is free to be reused. */
387 struct x_bitmap_record
392 /* Record some info about this pixmap. */
393 int height
, width
, depth
;
396 /* Pointer to bitmap records. */
397 static struct x_bitmap_record
*x_bitmaps
;
399 /* Allocated size of x_bitmaps. */
400 static int x_bitmaps_size
;
402 /* Last used bitmap index. */
403 static int x_bitmaps_last
;
405 /* Count of free bitmaps before X_BITMAPS_LAST. */
406 static int x_bitmaps_free
;
408 /* Functions to access the contents of a bitmap, given an id. */
411 x_bitmap_height (f
, id
)
415 return x_bitmaps
[id
- 1].height
;
419 x_bitmap_width (f
, id
)
423 return x_bitmaps
[id
- 1].width
;
427 x_bitmap_pixmap (f
, id
)
431 return x_bitmaps
[id
- 1].pixmap
;
435 /* Allocate a new bitmap record. Returns index of new record. */
438 x_allocate_bitmap_record ()
440 if (x_bitmaps
== NULL
)
444 = (struct x_bitmap_record
*) xmalloc (x_bitmaps_size
* sizeof (struct x_bitmap_record
));
449 if (x_bitmaps_last
< x_bitmaps_size
)
450 return ++x_bitmaps_last
;
452 if (x_bitmaps_free
> 0)
455 for (i
= 0; i
< x_bitmaps_size
; ++i
)
457 if (x_bitmaps
[i
].refcount
== 0)
466 x_bitmaps
= (struct x_bitmap_record
*) xrealloc (x_bitmaps
, x_bitmaps_size
* sizeof (struct x_bitmap_record
));
467 return ++x_bitmaps_last
;
470 /* Add one reference to the reference count of the bitmap with id ID. */
473 x_reference_bitmap (f
, id
)
477 ++x_bitmaps
[id
- 1].refcount
;
480 /* Create a bitmap for frame F from a HEIGHT x WIDTH array of bits at BITS. */
483 x_create_bitmap_from_data (f
, bits
, width
, height
)
486 unsigned int width
, height
;
491 bitmap
= XCreateBitmapFromData (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
492 bits
, width
, height
);
497 id
= x_allocate_bitmap_record ();
498 x_bitmaps
[id
- 1].pixmap
= bitmap
;
499 x_bitmaps
[id
- 1].file
= NULL
;
500 x_bitmaps
[id
- 1].refcount
= 1;
501 x_bitmaps
[id
- 1].depth
= 1;
502 x_bitmaps
[id
- 1].height
= height
;
503 x_bitmaps
[id
- 1].width
= width
;
508 /* Create bitmap from file FILE for frame F. */
511 x_create_bitmap_from_file (f
, file
)
515 unsigned int width
, height
;
517 int xhot
, yhot
, result
, id
;
522 /* Look for an existing bitmap with the same name. */
523 for (id
= 0; id
< x_bitmaps_last
; ++id
)
525 if (x_bitmaps
[id
].refcount
526 && x_bitmaps
[id
].file
527 && !strcmp (x_bitmaps
[id
].file
, (char *) XSTRING (file
)->data
))
529 ++x_bitmaps
[id
].refcount
;
534 /* Search bitmap-file-path for the file, if appropriate. */
535 fd
= openp (Vx_bitmap_file_path
, file
, "", &found
, 0);
540 filename
= (char *) XSTRING (found
)->data
;
542 result
= XReadBitmapFile (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
543 filename
, &width
, &height
, &bitmap
, &xhot
, &yhot
);
544 if (result
!= BitmapSuccess
)
547 id
= x_allocate_bitmap_record ();
548 x_bitmaps
[id
- 1].pixmap
= bitmap
;
549 x_bitmaps
[id
- 1].refcount
= 1;
550 x_bitmaps
[id
- 1].file
= (char *) xmalloc (XSTRING (file
)->size
+ 1);
551 x_bitmaps
[id
- 1].depth
= 1;
552 x_bitmaps
[id
- 1].height
= height
;
553 x_bitmaps
[id
- 1].width
= width
;
554 strcpy (x_bitmaps
[id
- 1].file
, XSTRING (file
)->data
);
559 /* Remove reference to bitmap with id number ID. */
562 x_destroy_bitmap (f
, id
)
568 --x_bitmaps
[id
- 1].refcount
;
569 if (! x_bitmaps
[id
- 1].refcount
)
571 XFreePixmap (FRAME_X_DISPLAY (f
), x_bitmaps
[id
- 1].pixmap
);
572 if (x_bitmaps
[id
- 1].file
)
574 free (x_bitmaps
[id
- 1].file
);
575 x_bitmaps
[id
- 1].file
= NULL
;
581 /* Return the actual X pixmap number for a given bitmap id. */
587 return x_bitmaps
[id
- 1].pixmap
;
590 /* Connect the frame-parameter names for X frames
591 to the ways of passing the parameter values to the window system.
593 The name of a parameter, as a Lisp symbol,
594 has an `x-frame-parameter' property which is an integer in Lisp
595 but can be interpreted as an `enum x_frame_parm' in C. */
599 X_PARM_FOREGROUND_COLOR
,
600 X_PARM_BACKGROUND_COLOR
,
607 X_PARM_INTERNAL_BORDER_WIDTH
,
611 X_PARM_VERT_SCROLL_BAR
,
613 X_PARM_MENU_BAR_LINES
617 struct x_frame_parm_table
620 void (*setter
)( /* struct frame *frame, Lisp_Object val, oldval */ );
623 void x_set_foreground_color ();
624 void x_set_background_color ();
625 void x_set_mouse_color ();
626 void x_set_cursor_color ();
627 void x_set_border_color ();
628 void x_set_cursor_type ();
629 void x_set_icon_type ();
631 void x_set_border_width ();
632 void x_set_internal_border_width ();
633 void x_explicitly_set_name ();
634 void x_set_autoraise ();
635 void x_set_autolower ();
636 void x_set_vertical_scroll_bars ();
637 void x_set_visibility ();
638 void x_set_menu_bar_lines ();
639 void x_set_scroll_bar_width ();
640 void x_set_unsplittable ();
642 static struct x_frame_parm_table x_frame_parms
[] =
644 "foreground-color", x_set_foreground_color
,
645 "background-color", x_set_background_color
,
646 "mouse-color", x_set_mouse_color
,
647 "cursor-color", x_set_cursor_color
,
648 "border-color", x_set_border_color
,
649 "cursor-type", x_set_cursor_type
,
650 "icon-type", x_set_icon_type
,
652 "border-width", x_set_border_width
,
653 "internal-border-width", x_set_internal_border_width
,
654 "name", x_explicitly_set_name
,
655 "auto-raise", x_set_autoraise
,
656 "auto-lower", x_set_autolower
,
657 "vertical-scroll-bars", x_set_vertical_scroll_bars
,
658 "visibility", x_set_visibility
,
659 "menu-bar-lines", x_set_menu_bar_lines
,
660 "scroll-bar-width", x_set_scroll_bar_width
,
661 "unsplittable", x_set_unsplittable
,
664 /* Attach the `x-frame-parameter' properties to
665 the Lisp symbol names of parameters relevant to X. */
667 init_x_parm_symbols ()
671 for (i
= 0; i
< sizeof (x_frame_parms
) / sizeof (x_frame_parms
[0]); i
++)
672 Fput (intern (x_frame_parms
[i
].name
), Qx_frame_parameter
,
676 /* Change the parameters of FRAME as specified by ALIST.
677 If a parameter is not specially recognized, do nothing;
678 otherwise call the `x_set_...' function for that parameter. */
681 x_set_frame_parameters (f
, alist
)
687 /* If both of these parameters are present, it's more efficient to
688 set them both at once. So we wait until we've looked at the
689 entire list before we set them. */
690 Lisp_Object width
, height
;
693 Lisp_Object left
, top
;
695 /* Record in these vectors all the parms specified. */
699 int left_no_change
= 0, top_no_change
= 0;
702 for (tail
= alist
; CONSP (tail
); tail
= Fcdr (tail
))
705 parms
= (Lisp_Object
*) alloca (i
* sizeof (Lisp_Object
));
706 values
= (Lisp_Object
*) alloca (i
* sizeof (Lisp_Object
));
708 /* Extract parm names and values into those vectors. */
711 for (tail
= alist
; CONSP (tail
); tail
= Fcdr (tail
))
713 Lisp_Object elt
, prop
, val
;
716 parms
[i
] = Fcar (elt
);
717 values
[i
] = Fcdr (elt
);
721 width
= height
= top
= left
= Qunbound
;
723 /* Now process them in reverse of specified order. */
724 for (i
--; i
>= 0; i
--)
726 Lisp_Object prop
, val
;
731 if (EQ (prop
, Qwidth
))
733 else if (EQ (prop
, Qheight
))
735 else if (EQ (prop
, Qtop
))
737 else if (EQ (prop
, Qleft
))
741 register Lisp_Object param_index
, old_value
;
743 param_index
= Fget (prop
, Qx_frame_parameter
);
744 old_value
= get_frame_param (f
, prop
);
745 store_frame_param (f
, prop
, val
);
746 if (INTEGERP (param_index
)
747 && XINT (param_index
) >= 0
748 && (XINT (param_index
)
749 < sizeof (x_frame_parms
)/sizeof (x_frame_parms
[0])))
750 (*x_frame_parms
[XINT (param_index
)].setter
)(f
, val
, old_value
);
754 /* Don't die if just one of these was set. */
755 if (EQ (left
, Qunbound
))
758 if (f
->display
.x
->left_pos
< 0)
759 left
= Fcons (Qplus
, Fcons (make_number (f
->display
.x
->left_pos
), Qnil
));
761 XSETINT (left
, f
->display
.x
->left_pos
);
763 if (EQ (top
, Qunbound
))
766 if (f
->display
.x
->top_pos
< 0)
767 top
= Fcons (Qplus
, Fcons (make_number (f
->display
.x
->top_pos
), Qnil
));
769 XSETINT (top
, f
->display
.x
->top_pos
);
772 /* Don't die if just one of these was set. */
773 if (EQ (width
, Qunbound
))
774 XSETINT (width
, FRAME_WIDTH (f
));
775 if (EQ (height
, Qunbound
))
776 XSETINT (height
, FRAME_HEIGHT (f
));
778 /* Don't set these parameters these unless they've been explicitly
779 specified. The window might be mapped or resized while we're in
780 this function, and we don't want to override that unless the lisp
781 code has asked for it.
783 Don't set these parameters unless they actually differ from the
784 window's current parameters; the window may not actually exist
789 check_frame_size (f
, &height
, &width
);
791 XSETFRAME (frame
, f
);
793 if ((NUMBERP (width
) && XINT (width
) != FRAME_WIDTH (f
))
794 || (NUMBERP (height
) && XINT (height
) != FRAME_HEIGHT (f
)))
795 Fset_frame_size (frame
, width
, height
);
797 if ((!NILP (left
) || !NILP (top
))
798 && ! (left_no_change
&& top_no_change
)
799 && ! (NUMBERP (left
) && XINT (left
) == f
->display
.x
->left_pos
800 && NUMBERP (top
) && XINT (top
) == f
->display
.x
->top_pos
))
805 /* Record the signs. */
806 f
->display
.x
->size_hint_flags
&= ~ (XNegative
| YNegative
);
807 if (EQ (left
, Qminus
))
808 f
->display
.x
->size_hint_flags
|= XNegative
;
809 else if (INTEGERP (left
))
811 leftpos
= XINT (left
);
813 f
->display
.x
->size_hint_flags
|= XNegative
;
815 else if (CONSP (left
) && EQ (XCONS (left
)->car
, Qminus
)
816 && CONSP (XCONS (left
)->cdr
)
817 && INTEGERP (XCONS (XCONS (left
)->cdr
)->car
))
819 leftpos
= - XINT (XCONS (XCONS (left
)->cdr
)->car
);
820 f
->display
.x
->size_hint_flags
|= XNegative
;
822 else if (CONSP (left
) && EQ (XCONS (left
)->car
, Qplus
)
823 && CONSP (XCONS (left
)->cdr
)
824 && INTEGERP (XCONS (XCONS (left
)->cdr
)->car
))
826 leftpos
= XINT (XCONS (XCONS (left
)->cdr
)->car
);
829 if (EQ (top
, Qminus
))
830 f
->display
.x
->size_hint_flags
|= YNegative
;
831 else if (INTEGERP (top
))
835 f
->display
.x
->size_hint_flags
|= YNegative
;
837 else if (CONSP (top
) && EQ (XCONS (top
)->car
, Qminus
)
838 && CONSP (XCONS (top
)->cdr
)
839 && INTEGERP (XCONS (XCONS (top
)->cdr
)->car
))
841 toppos
= - XINT (XCONS (XCONS (top
)->cdr
)->car
);
842 f
->display
.x
->size_hint_flags
|= YNegative
;
844 else if (CONSP (top
) && EQ (XCONS (top
)->car
, Qplus
)
845 && CONSP (XCONS (top
)->cdr
)
846 && INTEGERP (XCONS (XCONS (top
)->cdr
)->car
))
848 toppos
= XINT (XCONS (XCONS (top
)->cdr
)->car
);
852 /* Store the numeric value of the position. */
853 f
->display
.x
->top_pos
= toppos
;
854 f
->display
.x
->left_pos
= leftpos
;
856 f
->display
.x
->win_gravity
= NorthWestGravity
;
858 /* Actually set that position, and convert to absolute. */
859 x_set_offset (f
, leftpos
, toppos
, 0);
864 /* Store the positions of frame F into XPTR and YPTR.
865 These are the positions of the containing window manager window,
866 not Emacs's own window. */
869 x_real_positions (f
, xptr
, yptr
)
873 int win_x
= 0, win_y
= 0;
876 /* This is pretty gross, but seems to be the easiest way out of
877 the problem that arises when restarting window-managers. */
880 Window outer
= XtWindow (f
->display
.x
->widget
);
882 Window outer
= f
->display
.x
->window_desc
;
884 Window tmp_root_window
;
885 Window
*tmp_children
;
888 XQueryTree (FRAME_X_DISPLAY (f
), outer
, &tmp_root_window
,
889 &f
->display
.x
->parent_desc
,
890 &tmp_children
, &tmp_nchildren
);
891 xfree (tmp_children
);
893 /* Find the position of the outside upper-left corner of
894 the inner window, with respect to the outer window. */
895 if (f
->display
.x
->parent_desc
!= FRAME_X_DISPLAY_INFO (f
)->root_window
)
898 XTranslateCoordinates (FRAME_X_DISPLAY (f
),
900 /* From-window, to-window. */
902 XtWindow (f
->display
.x
->widget
),
904 f
->display
.x
->window_desc
,
906 f
->display
.x
->parent_desc
,
908 /* From-position, to-position. */
909 0, 0, &win_x
, &win_y
,
915 win_x
+= f
->display
.x
->border_width
;
916 win_y
+= f
->display
.x
->border_width
;
918 *xptr
= f
->display
.x
->left_pos
- win_x
;
919 *yptr
= f
->display
.x
->top_pos
- win_y
;
922 /* Insert a description of internally-recorded parameters of frame X
923 into the parameter alist *ALISTPTR that is to be given to the user.
924 Only parameters that are specific to the X window system
925 and whose values are not correctly recorded in the frame's
926 param_alist need to be considered here. */
928 x_report_frame_params (f
, alistptr
)
930 Lisp_Object
*alistptr
;
934 store_in_alist (alistptr
, Qleft
, make_number (f
->display
.x
->left_pos
));
935 store_in_alist (alistptr
, Qtop
, make_number (f
->display
.x
->top_pos
));
936 store_in_alist (alistptr
, Qborder_width
,
937 make_number (f
->display
.x
->border_width
));
938 store_in_alist (alistptr
, Qinternal_border_width
,
939 make_number (f
->display
.x
->internal_border_width
));
940 sprintf (buf
, "%ld", (long) FRAME_X_WINDOW (f
));
941 store_in_alist (alistptr
, Qwindow_id
,
943 FRAME_SAMPLE_VISIBILITY (f
);
944 store_in_alist (alistptr
, Qvisibility
,
945 (FRAME_VISIBLE_P (f
) ? Qt
946 : FRAME_ICONIFIED_P (f
) ? Qicon
: Qnil
));
949 /* Decide if color named COLOR is valid for the display associated with
950 the selected frame; if so, return the rgb values in COLOR_DEF.
951 If ALLOC is nonzero, allocate a new colormap cell. */
954 defined_color (f
, color
, color_def
, alloc
)
961 Colormap screen_colormap
;
965 = DefaultColormap (FRAME_X_DISPLAY (f
),
966 XDefaultScreen (FRAME_X_DISPLAY (f
)));
968 foo
= XParseColor (FRAME_X_DISPLAY (f
), screen_colormap
, color
, color_def
);
970 foo
= XAllocColor (FRAME_X_DISPLAY (f
), screen_colormap
, color_def
);
979 /* Given a string ARG naming a color, compute a pixel value from it
980 suitable for screen F.
981 If F is not a color screen, return DEF (default) regardless of what
985 x_decode_color (f
, arg
, def
)
992 CHECK_STRING (arg
, 0);
994 if (strcmp (XSTRING (arg
)->data
, "black") == 0)
995 return BLACK_PIX_DEFAULT (f
);
996 else if (strcmp (XSTRING (arg
)->data
, "white") == 0)
997 return WHITE_PIX_DEFAULT (f
);
999 if (FRAME_X_DISPLAY_INFO (f
)->n_planes
== 1)
1002 if (defined_color (f
, XSTRING (arg
)->data
, &cdef
, 1))
1005 Fsignal (Qundefined_color
, Fcons (arg
, Qnil
));
1008 /* Functions called only from `x_set_frame_param'
1009 to set individual parameters.
1011 If FRAME_X_WINDOW (f) is 0,
1012 the frame is being created and its X-window does not exist yet.
1013 In that case, just record the parameter's new value
1014 in the standard place; do not attempt to change the window. */
1017 x_set_foreground_color (f
, arg
, oldval
)
1019 Lisp_Object arg
, oldval
;
1021 f
->display
.x
->foreground_pixel
1022 = x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1023 if (FRAME_X_WINDOW (f
) != 0)
1026 XSetForeground (FRAME_X_DISPLAY (f
), f
->display
.x
->normal_gc
,
1027 f
->display
.x
->foreground_pixel
);
1028 XSetBackground (FRAME_X_DISPLAY (f
), f
->display
.x
->reverse_gc
,
1029 f
->display
.x
->foreground_pixel
);
1031 recompute_basic_faces (f
);
1032 if (FRAME_VISIBLE_P (f
))
1038 x_set_background_color (f
, arg
, oldval
)
1040 Lisp_Object arg
, oldval
;
1045 f
->display
.x
->background_pixel
1046 = x_decode_color (f
, arg
, WHITE_PIX_DEFAULT (f
));
1048 if (FRAME_X_WINDOW (f
) != 0)
1051 /* The main frame area. */
1052 XSetBackground (FRAME_X_DISPLAY (f
), f
->display
.x
->normal_gc
,
1053 f
->display
.x
->background_pixel
);
1054 XSetForeground (FRAME_X_DISPLAY (f
), f
->display
.x
->reverse_gc
,
1055 f
->display
.x
->background_pixel
);
1056 XSetForeground (FRAME_X_DISPLAY (f
), f
->display
.x
->cursor_gc
,
1057 f
->display
.x
->background_pixel
);
1058 XSetWindowBackground (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1059 f
->display
.x
->background_pixel
);
1062 for (bar
= FRAME_SCROLL_BARS (f
); !NILP (bar
);
1063 bar
= XSCROLL_BAR (bar
)->next
)
1064 XSetWindowBackground (FRAME_X_DISPLAY (f
),
1065 SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar
)),
1066 f
->display
.x
->background_pixel
);
1070 recompute_basic_faces (f
);
1072 if (FRAME_VISIBLE_P (f
))
1078 x_set_mouse_color (f
, arg
, oldval
)
1080 Lisp_Object arg
, oldval
;
1082 Cursor cursor
, nontext_cursor
, mode_cursor
, cross_cursor
;
1085 if (!EQ (Qnil
, arg
))
1086 f
->display
.x
->mouse_pixel
1087 = x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1088 mask_color
= f
->display
.x
->background_pixel
;
1089 /* No invisible pointers. */
1090 if (mask_color
== f
->display
.x
->mouse_pixel
1091 && mask_color
== f
->display
.x
->background_pixel
)
1092 f
->display
.x
->mouse_pixel
= f
->display
.x
->foreground_pixel
;
1096 /* It's not okay to crash if the user selects a screwy cursor. */
1099 if (!EQ (Qnil
, Vx_pointer_shape
))
1101 CHECK_NUMBER (Vx_pointer_shape
, 0);
1102 cursor
= XCreateFontCursor (FRAME_X_DISPLAY (f
), XINT (Vx_pointer_shape
));
1105 cursor
= XCreateFontCursor (FRAME_X_DISPLAY (f
), XC_xterm
);
1106 x_check_errors (f
, "bad text pointer cursor: %s");
1108 if (!EQ (Qnil
, Vx_nontext_pointer_shape
))
1110 CHECK_NUMBER (Vx_nontext_pointer_shape
, 0);
1111 nontext_cursor
= XCreateFontCursor (FRAME_X_DISPLAY (f
),
1112 XINT (Vx_nontext_pointer_shape
));
1115 nontext_cursor
= XCreateFontCursor (FRAME_X_DISPLAY (f
), XC_left_ptr
);
1116 x_check_errors (f
, "bad nontext pointer cursor: %s");
1118 if (!EQ (Qnil
, Vx_mode_pointer_shape
))
1120 CHECK_NUMBER (Vx_mode_pointer_shape
, 0);
1121 mode_cursor
= XCreateFontCursor (FRAME_X_DISPLAY (f
),
1122 XINT (Vx_mode_pointer_shape
));
1125 mode_cursor
= XCreateFontCursor (FRAME_X_DISPLAY (f
), XC_xterm
);
1126 x_check_errors (f
, "bad modeline pointer cursor: %s");
1128 if (!EQ (Qnil
, Vx_sensitive_text_pointer_shape
))
1130 CHECK_NUMBER (Vx_sensitive_text_pointer_shape
, 0);
1132 = XCreateFontCursor (FRAME_X_DISPLAY (f
),
1133 XINT (Vx_sensitive_text_pointer_shape
));
1136 cross_cursor
= XCreateFontCursor (FRAME_X_DISPLAY (f
), XC_crosshair
);
1138 /* Check and report errors with the above calls. */
1139 x_check_errors (f
, "can't set cursor shape: %s");
1140 x_uncatch_errors (f
);
1143 XColor fore_color
, back_color
;
1145 fore_color
.pixel
= f
->display
.x
->mouse_pixel
;
1146 back_color
.pixel
= mask_color
;
1147 XQueryColor (FRAME_X_DISPLAY (f
),
1148 DefaultColormap (FRAME_X_DISPLAY (f
),
1149 DefaultScreen (FRAME_X_DISPLAY (f
))),
1151 XQueryColor (FRAME_X_DISPLAY (f
),
1152 DefaultColormap (FRAME_X_DISPLAY (f
),
1153 DefaultScreen (FRAME_X_DISPLAY (f
))),
1155 XRecolorCursor (FRAME_X_DISPLAY (f
), cursor
,
1156 &fore_color
, &back_color
);
1157 XRecolorCursor (FRAME_X_DISPLAY (f
), nontext_cursor
,
1158 &fore_color
, &back_color
);
1159 XRecolorCursor (FRAME_X_DISPLAY (f
), mode_cursor
,
1160 &fore_color
, &back_color
);
1161 XRecolorCursor (FRAME_X_DISPLAY (f
), cross_cursor
,
1162 &fore_color
, &back_color
);
1165 if (FRAME_X_WINDOW (f
) != 0)
1167 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), cursor
);
1170 if (cursor
!= f
->display
.x
->text_cursor
&& f
->display
.x
->text_cursor
!= 0)
1171 XFreeCursor (FRAME_X_DISPLAY (f
), f
->display
.x
->text_cursor
);
1172 f
->display
.x
->text_cursor
= cursor
;
1174 if (nontext_cursor
!= f
->display
.x
->nontext_cursor
1175 && f
->display
.x
->nontext_cursor
!= 0)
1176 XFreeCursor (FRAME_X_DISPLAY (f
), f
->display
.x
->nontext_cursor
);
1177 f
->display
.x
->nontext_cursor
= nontext_cursor
;
1179 if (mode_cursor
!= f
->display
.x
->modeline_cursor
1180 && f
->display
.x
->modeline_cursor
!= 0)
1181 XFreeCursor (FRAME_X_DISPLAY (f
), f
->display
.x
->modeline_cursor
);
1182 f
->display
.x
->modeline_cursor
= mode_cursor
;
1183 if (cross_cursor
!= f
->display
.x
->cross_cursor
1184 && f
->display
.x
->cross_cursor
!= 0)
1185 XFreeCursor (FRAME_X_DISPLAY (f
), f
->display
.x
->cross_cursor
);
1186 f
->display
.x
->cross_cursor
= cross_cursor
;
1188 XFlush (FRAME_X_DISPLAY (f
));
1193 x_set_cursor_color (f
, arg
, oldval
)
1195 Lisp_Object arg
, oldval
;
1197 unsigned long fore_pixel
;
1199 if (!EQ (Vx_cursor_fore_pixel
, Qnil
))
1200 fore_pixel
= x_decode_color (f
, Vx_cursor_fore_pixel
,
1201 WHITE_PIX_DEFAULT (f
));
1203 fore_pixel
= f
->display
.x
->background_pixel
;
1204 f
->display
.x
->cursor_pixel
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1206 /* Make sure that the cursor color differs from the background color. */
1207 if (f
->display
.x
->cursor_pixel
== f
->display
.x
->background_pixel
)
1209 f
->display
.x
->cursor_pixel
= f
->display
.x
->mouse_pixel
;
1210 if (f
->display
.x
->cursor_pixel
== fore_pixel
)
1211 fore_pixel
= f
->display
.x
->background_pixel
;
1213 f
->display
.x
->cursor_foreground_pixel
= fore_pixel
;
1215 if (FRAME_X_WINDOW (f
) != 0)
1218 XSetBackground (FRAME_X_DISPLAY (f
), f
->display
.x
->cursor_gc
,
1219 f
->display
.x
->cursor_pixel
);
1220 XSetForeground (FRAME_X_DISPLAY (f
), f
->display
.x
->cursor_gc
,
1224 if (FRAME_VISIBLE_P (f
))
1226 x_display_cursor (f
, 0);
1227 x_display_cursor (f
, 1);
1232 /* Set the border-color of frame F to value described by ARG.
1233 ARG can be a string naming a color.
1234 The border-color is used for the border that is drawn by the X server.
1235 Note that this does not fully take effect if done before
1236 F has an x-window; it must be redone when the window is created.
1238 Note: this is done in two routines because of the way X10 works.
1240 Note: under X11, this is normally the province of the window manager,
1241 and so emacs' border colors may be overridden. */
1244 x_set_border_color (f
, arg
, oldval
)
1246 Lisp_Object arg
, oldval
;
1251 CHECK_STRING (arg
, 0);
1252 str
= XSTRING (arg
)->data
;
1254 pix
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1256 x_set_border_pixel (f
, pix
);
1259 /* Set the border-color of frame F to pixel value PIX.
1260 Note that this does not fully take effect if done before
1261 F has an x-window. */
1263 x_set_border_pixel (f
, pix
)
1267 f
->display
.x
->border_pixel
= pix
;
1269 if (FRAME_X_WINDOW (f
) != 0 && f
->display
.x
->border_width
> 0)
1275 XSetWindowBorder (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1279 if (FRAME_VISIBLE_P (f
))
1285 x_set_cursor_type (f
, arg
, oldval
)
1287 Lisp_Object arg
, oldval
;
1290 FRAME_DESIRED_CURSOR (f
) = bar_cursor
;
1295 FRAME_DESIRED_CURSOR (f
) = filled_box_cursor
;
1296 /* Error messages commented out because people have trouble fixing
1297 .Xdefaults with Emacs, when it has something bad in it. */
1301 ("the `cursor-type' frame parameter should be either `bar' or `box'");
1304 /* Make sure the cursor gets redrawn. This is overkill, but how
1305 often do people change cursor types? */
1306 update_mode_lines
++;
1310 x_set_icon_type (f
, arg
, oldval
)
1312 Lisp_Object arg
, oldval
;
1319 if (STRINGP (oldval
) && EQ (Fstring_equal (oldval
, arg
), Qt
))
1322 else if (!STRINGP (oldval
) && EQ (oldval
, Qnil
) == EQ (arg
, Qnil
))
1327 result
= x_text_icon (f
, 0);
1329 result
= x_bitmap_icon (f
, arg
);
1334 error ("No icon window available");
1337 /* If the window was unmapped (and its icon was mapped),
1338 the new icon is not mapped, so map the window in its stead. */
1339 if (FRAME_VISIBLE_P (f
))
1341 #ifdef USE_X_TOOLKIT
1342 XtPopup (f
->display
.x
->widget
, XtGrabNone
);
1344 XMapWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
1347 XFlush (FRAME_X_DISPLAY (f
));
1351 /* Return non-nil if frame F wants a bitmap icon. */
1359 tem
= assq_no_quit (Qicon_type
, f
->param_alist
);
1361 return XCONS (tem
)->cdr
;
1366 extern Lisp_Object
x_new_font ();
1369 x_set_font (f
, arg
, oldval
)
1371 Lisp_Object arg
, oldval
;
1375 CHECK_STRING (arg
, 1);
1378 result
= x_new_font (f
, XSTRING (arg
)->data
);
1381 if (EQ (result
, Qnil
))
1382 error ("Font \"%s\" is not defined", XSTRING (arg
)->data
);
1383 else if (EQ (result
, Qt
))
1384 error ("the characters of the given font have varying widths");
1385 else if (STRINGP (result
))
1387 recompute_basic_faces (f
);
1388 store_frame_param (f
, Qfont
, result
);
1395 x_set_border_width (f
, arg
, oldval
)
1397 Lisp_Object arg
, oldval
;
1399 CHECK_NUMBER (arg
, 0);
1401 if (XINT (arg
) == f
->display
.x
->border_width
)
1404 if (FRAME_X_WINDOW (f
) != 0)
1405 error ("Cannot change the border width of a window");
1407 f
->display
.x
->border_width
= XINT (arg
);
1411 x_set_internal_border_width (f
, arg
, oldval
)
1413 Lisp_Object arg
, oldval
;
1416 int old
= f
->display
.x
->internal_border_width
;
1418 CHECK_NUMBER (arg
, 0);
1419 f
->display
.x
->internal_border_width
= XINT (arg
);
1420 if (f
->display
.x
->internal_border_width
< 0)
1421 f
->display
.x
->internal_border_width
= 0;
1423 if (f
->display
.x
->internal_border_width
== old
)
1426 if (FRAME_X_WINDOW (f
) != 0)
1429 x_set_window_size (f
, 0, f
->width
, f
->height
);
1431 x_set_resize_hint (f
);
1433 XFlush (FRAME_X_DISPLAY (f
));
1435 SET_FRAME_GARBAGED (f
);
1440 x_set_visibility (f
, value
, oldval
)
1442 Lisp_Object value
, oldval
;
1445 XSETFRAME (frame
, f
);
1448 Fmake_frame_invisible (frame
, Qt
);
1449 else if (EQ (value
, Qicon
))
1450 Ficonify_frame (frame
);
1452 Fmake_frame_visible (frame
);
1456 x_set_menu_bar_lines_1 (window
, n
)
1460 struct window
*w
= XWINDOW (window
);
1462 XSETFASTINT (w
->top
, XFASTINT (w
->top
) + n
);
1463 XSETFASTINT (w
->height
, XFASTINT (w
->height
) - n
);
1465 /* Handle just the top child in a vertical split. */
1466 if (!NILP (w
->vchild
))
1467 x_set_menu_bar_lines_1 (w
->vchild
, n
);
1469 /* Adjust all children in a horizontal split. */
1470 for (window
= w
->hchild
; !NILP (window
); window
= w
->next
)
1472 w
= XWINDOW (window
);
1473 x_set_menu_bar_lines_1 (window
, n
);
1478 x_set_menu_bar_lines (f
, value
, oldval
)
1480 Lisp_Object value
, oldval
;
1483 int olines
= FRAME_MENU_BAR_LINES (f
);
1485 /* Right now, menu bars don't work properly in minibuf-only frames;
1486 most of the commands try to apply themselves to the minibuffer
1487 frame itslef, and get an error because you can't switch buffers
1488 in or split the minibuffer window. */
1489 if (FRAME_MINIBUF_ONLY_P (f
))
1492 if (INTEGERP (value
))
1493 nlines
= XINT (value
);
1497 #ifdef USE_X_TOOLKIT
1498 FRAME_MENU_BAR_LINES (f
) = 0;
1500 FRAME_EXTERNAL_MENU_BAR (f
) = 1;
1503 if (FRAME_EXTERNAL_MENU_BAR (f
) == 1)
1504 free_frame_menubar (f
);
1505 FRAME_EXTERNAL_MENU_BAR (f
) = 0;
1506 f
->display
.x
->menubar_widget
= 0;
1508 #else /* not USE_X_TOOLKIT */
1509 FRAME_MENU_BAR_LINES (f
) = nlines
;
1510 x_set_menu_bar_lines_1 (f
->root_window
, nlines
- olines
);
1511 #endif /* not USE_X_TOOLKIT */
1514 /* Change the name of frame F to NAME. If NAME is nil, set F's name to
1517 If EXPLICIT is non-zero, that indicates that lisp code is setting the
1518 name; if NAME is a string, set F's name to NAME and set
1519 F->explicit_name; if NAME is Qnil, then clear F->explicit_name.
1521 If EXPLICIT is zero, that indicates that Emacs redisplay code is
1522 suggesting a new name, which lisp code should override; if
1523 F->explicit_name is set, ignore the new name; otherwise, set it. */
1526 x_set_name (f
, name
, explicit)
1531 /* Make sure that requests from lisp code override requests from
1532 Emacs redisplay code. */
1535 /* If we're switching from explicit to implicit, we had better
1536 update the mode lines and thereby update the title. */
1537 if (f
->explicit_name
&& NILP (name
))
1538 update_mode_lines
= 1;
1540 f
->explicit_name
= ! NILP (name
);
1542 else if (f
->explicit_name
)
1545 /* If NAME is nil, set the name to the x_id_name. */
1548 /* Check for no change needed in this very common case
1549 before we do any consing. */
1550 if (!strcmp (x_id_name
, XSTRING (f
->name
)->data
))
1552 name
= build_string (x_id_name
);
1555 CHECK_STRING (name
, 0);
1557 /* Don't change the name if it's already NAME. */
1558 if (! NILP (Fstring_equal (name
, f
->name
)))
1561 if (FRAME_X_WINDOW (f
))
1567 text
.value
= XSTRING (name
)->data
;
1568 text
.encoding
= XA_STRING
;
1570 text
.nitems
= XSTRING (name
)->size
;
1571 #ifdef USE_X_TOOLKIT
1572 XSetWMName (FRAME_X_DISPLAY (f
),
1573 XtWindow (f
->display
.x
->widget
), &text
);
1574 XSetWMIconName (FRAME_X_DISPLAY (f
), XtWindow (f
->display
.x
->widget
),
1576 #else /* not USE_X_TOOLKIT */
1577 XSetWMName (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), &text
);
1578 XSetWMIconName (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), &text
);
1579 #endif /* not USE_X_TOOLKIT */
1581 #else /* not HAVE_X11R4 */
1582 XSetIconName (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1583 XSTRING (name
)->data
);
1584 XStoreName (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1585 XSTRING (name
)->data
);
1586 #endif /* not HAVE_X11R4 */
1593 /* This function should be called when the user's lisp code has
1594 specified a name for the frame; the name will override any set by the
1597 x_explicitly_set_name (f
, arg
, oldval
)
1599 Lisp_Object arg
, oldval
;
1601 x_set_name (f
, arg
, 1);
1604 /* This function should be called by Emacs redisplay code to set the
1605 name; names set this way will never override names set by the user's
1608 x_implicitly_set_name (f
, arg
, oldval
)
1610 Lisp_Object arg
, oldval
;
1612 x_set_name (f
, arg
, 0);
1616 x_set_autoraise (f
, arg
, oldval
)
1618 Lisp_Object arg
, oldval
;
1620 f
->auto_raise
= !EQ (Qnil
, arg
);
1624 x_set_autolower (f
, arg
, oldval
)
1626 Lisp_Object arg
, oldval
;
1628 f
->auto_lower
= !EQ (Qnil
, arg
);
1632 x_set_unsplittable (f
, arg
, oldval
)
1634 Lisp_Object arg
, oldval
;
1636 f
->no_split
= !NILP (arg
);
1640 x_set_vertical_scroll_bars (f
, arg
, oldval
)
1642 Lisp_Object arg
, oldval
;
1644 if (NILP (arg
) != ! FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
1646 FRAME_HAS_VERTICAL_SCROLL_BARS (f
) = ! NILP (arg
);
1648 /* We set this parameter before creating the X window for the
1649 frame, so we can get the geometry right from the start.
1650 However, if the window hasn't been created yet, we shouldn't
1651 call x_set_window_size. */
1652 if (FRAME_X_WINDOW (f
))
1653 x_set_window_size (f
, 0, FRAME_WIDTH (f
), FRAME_HEIGHT (f
));
1658 x_set_scroll_bar_width (f
, arg
, oldval
)
1660 Lisp_Object arg
, oldval
;
1664 FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) = 0;
1665 FRAME_SCROLL_BAR_COLS (f
) = 2;
1667 else if (INTEGERP (arg
) && XINT (arg
) > 0
1668 && XFASTINT (arg
) != FRAME_SCROLL_BAR_PIXEL_WIDTH (f
))
1670 int wid
= FONT_WIDTH (f
->display
.x
->font
);
1671 FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) = XFASTINT (arg
);
1672 FRAME_SCROLL_BAR_COLS (f
) = (XFASTINT (arg
) + wid
-1) / wid
;
1673 if (FRAME_X_WINDOW (f
))
1674 x_set_window_size (f
, 0, FRAME_WIDTH (f
), FRAME_HEIGHT (f
));
1678 /* Subroutines of creating an X frame. */
1680 /* Make sure that Vx_resource_name is set to a reasonable value. */
1682 validate_x_resource_name ()
1684 if (STRINGP (Vx_resource_name
))
1686 int len
= XSTRING (Vx_resource_name
)->size
;
1687 unsigned char *p
= XSTRING (Vx_resource_name
)->data
;
1690 /* Allow only letters, digits, - and _,
1691 because those are all that X allows. */
1692 for (i
= 0; i
< len
; i
++)
1695 if (! ((c
>= 'a' && c
<= 'z')
1696 || (c
>= 'A' && c
<= 'Z')
1697 || (c
>= '0' && c
<= '9')
1698 || c
== '-' || c
== '_'))
1704 Vx_resource_name
= make_string ("emacs", 5);
1708 extern char *x_get_string_resource ();
1710 DEFUN ("x-get-resource", Fx_get_resource
, Sx_get_resource
, 2, 4, 0,
1711 "Return the value of ATTRIBUTE, of class CLASS, from the X defaults database.\n\
1712 This uses `INSTANCE.ATTRIBUTE' as the key and `Emacs.CLASS' as the\n\
1713 class, where INSTANCE is the name under which Emacs was invoked, or\n\
1714 the name specified by the `-name' or `-rn' command-line arguments.\n\
1716 The optional arguments COMPONENT and SUBCLASS add to the key and the\n\
1717 class, respectively. You must specify both of them or neither.\n\
1718 If you specify them, the key is `INSTANCE.COMPONENT.ATTRIBUTE'\n\
1719 and the class is `Emacs.CLASS.SUBCLASS'.")
1720 (attribute
, class, component
, subclass
)
1721 Lisp_Object attribute
, class, component
, subclass
;
1723 register char *value
;
1726 Lisp_Object resname
;
1730 CHECK_STRING (attribute
, 0);
1731 CHECK_STRING (class, 0);
1733 if (!NILP (component
))
1734 CHECK_STRING (component
, 1);
1735 if (!NILP (subclass
))
1736 CHECK_STRING (subclass
, 2);
1737 if (NILP (component
) != NILP (subclass
))
1738 error ("x-get-resource: must specify both COMPONENT and SUBCLASS or neither");
1740 validate_x_resource_name ();
1741 resname
= Vx_resource_name
;
1743 if (NILP (component
))
1745 /* Allocate space for the components, the dots which separate them,
1746 and the final '\0'. */
1747 name_key
= (char *) alloca (XSTRING (resname
)->size
1748 + XSTRING (attribute
)->size
1750 class_key
= (char *) alloca ((sizeof (EMACS_CLASS
) - 1)
1751 + XSTRING (class)->size
1754 sprintf (name_key
, "%s.%s",
1755 XSTRING (resname
)->data
,
1756 XSTRING (attribute
)->data
);
1757 sprintf (class_key
, "%s.%s",
1759 XSTRING (class)->data
);
1763 name_key
= (char *) alloca (XSTRING (resname
)->size
1764 + XSTRING (component
)->size
1765 + XSTRING (attribute
)->size
1768 class_key
= (char *) alloca ((sizeof (EMACS_CLASS
) - 1)
1769 + XSTRING (class)->size
1770 + XSTRING (subclass
)->size
1773 sprintf (name_key
, "%s.%s.%s",
1774 XSTRING (resname
)->data
,
1775 XSTRING (component
)->data
,
1776 XSTRING (attribute
)->data
);
1777 sprintf (class_key
, "%s.%s.%s",
1779 XSTRING (class)->data
,
1780 XSTRING (subclass
)->data
);
1783 value
= x_get_string_resource (check_x_display_info (Qnil
)->xrdb
,
1784 name_key
, class_key
);
1786 if (value
!= (char *) 0)
1787 return build_string (value
);
1792 /* Used when C code wants a resource value. */
1795 x_get_resource_string (attribute
, class)
1796 char *attribute
, *class;
1798 register char *value
;
1802 /* Allocate space for the components, the dots which separate them,
1803 and the final '\0'. */
1804 name_key
= (char *) alloca (XSTRING (Vinvocation_name
)->size
1805 + strlen (attribute
) + 2);
1806 class_key
= (char *) alloca ((sizeof (EMACS_CLASS
) - 1)
1807 + strlen (class) + 2);
1809 sprintf (name_key
, "%s.%s",
1810 XSTRING (Vinvocation_name
)->data
,
1812 sprintf (class_key
, "%s.%s", EMACS_CLASS
, class);
1814 return x_get_string_resource (FRAME_X_DISPLAY_INFO (selected_frame
)->xrdb
,
1815 name_key
, class_key
);
1818 /* Types we might convert a resource string into. */
1821 number
, boolean
, string
, symbol
1824 /* Return the value of parameter PARAM.
1826 First search ALIST, then Vdefault_frame_alist, then the X defaults
1827 database, using ATTRIBUTE as the attribute name and CLASS as its class.
1829 Convert the resource to the type specified by desired_type.
1831 If no default is specified, return Qunbound. If you call
1832 x_get_arg, make sure you deal with Qunbound in a reasonable way,
1833 and don't let it get stored in any lisp-visible variables! */
1836 x_get_arg (alist
, param
, attribute
, class, type
)
1837 Lisp_Object alist
, param
;
1840 enum resource_types type
;
1842 register Lisp_Object tem
;
1844 tem
= Fassq (param
, alist
);
1846 tem
= Fassq (param
, Vdefault_frame_alist
);
1852 tem
= Fx_get_resource (build_string (attribute
),
1853 build_string (class),
1862 return make_number (atoi (XSTRING (tem
)->data
));
1865 tem
= Fdowncase (tem
);
1866 if (!strcmp (XSTRING (tem
)->data
, "on")
1867 || !strcmp (XSTRING (tem
)->data
, "true"))
1876 /* As a special case, we map the values `true' and `on'
1877 to Qt, and `false' and `off' to Qnil. */
1880 lower
= Fdowncase (tem
);
1881 if (!strcmp (XSTRING (lower
)->data
, "on")
1882 || !strcmp (XSTRING (lower
)->data
, "true"))
1884 else if (!strcmp (XSTRING (lower
)->data
, "off")
1885 || !strcmp (XSTRING (lower
)->data
, "false"))
1888 return Fintern (tem
, Qnil
);
1901 /* Record in frame F the specified or default value according to ALIST
1902 of the parameter named PARAM (a Lisp symbol).
1903 If no value is specified for PARAM, look for an X default for XPROP
1904 on the frame named NAME.
1905 If that is not found either, use the value DEFLT. */
1908 x_default_parameter (f
, alist
, prop
, deflt
, xprop
, xclass
, type
)
1915 enum resource_types type
;
1919 tem
= x_get_arg (alist
, prop
, xprop
, xclass
, type
);
1920 if (EQ (tem
, Qunbound
))
1922 x_set_frame_parameters (f
, Fcons (Fcons (prop
, tem
), Qnil
));
1926 DEFUN ("x-parse-geometry", Fx_parse_geometry
, Sx_parse_geometry
, 1, 1, 0,
1927 "Parse an X-style geometry string STRING.\n\
1928 Returns an alist of the form ((top . TOP), (left . LEFT) ... ).\n\
1929 The properties returned may include `top', `left', `height', and `width'.\n\
1930 The value of `left' or `top' may be an integer,\n\
1931 or a list (+ N) meaning N pixels relative to top/left corner,\n\
1932 or a list (- N) meaning -N pixels relative to bottom/right corner.")
1937 unsigned int width
, height
;
1940 CHECK_STRING (string
, 0);
1942 geometry
= XParseGeometry ((char *) XSTRING (string
)->data
,
1943 &x
, &y
, &width
, &height
);
1946 if (!!(geometry
& XValue
) != !!(geometry
& YValue
))
1947 error ("Must specify both x and y position, or neither");
1951 if (geometry
& XValue
)
1953 Lisp_Object element
;
1955 if (x
>= 0 && (geometry
& XNegative
))
1956 element
= Fcons (Qleft
, Fcons (Qminus
, Fcons (make_number (-x
), Qnil
)));
1957 else if (x
< 0 && ! (geometry
& XNegative
))
1958 element
= Fcons (Qleft
, Fcons (Qplus
, Fcons (make_number (x
), Qnil
)));
1960 element
= Fcons (Qleft
, make_number (x
));
1961 result
= Fcons (element
, result
);
1964 if (geometry
& YValue
)
1966 Lisp_Object element
;
1968 if (y
>= 0 && (geometry
& YNegative
))
1969 element
= Fcons (Qtop
, Fcons (Qminus
, Fcons (make_number (-y
), Qnil
)));
1970 else if (y
< 0 && ! (geometry
& YNegative
))
1971 element
= Fcons (Qtop
, Fcons (Qplus
, Fcons (make_number (y
), Qnil
)));
1973 element
= Fcons (Qtop
, make_number (y
));
1974 result
= Fcons (element
, result
);
1977 if (geometry
& WidthValue
)
1978 result
= Fcons (Fcons (Qwidth
, make_number (width
)), result
);
1979 if (geometry
& HeightValue
)
1980 result
= Fcons (Fcons (Qheight
, make_number (height
)), result
);
1985 /* Calculate the desired size and position of this window,
1986 and return the flags saying which aspects were specified.
1988 This function does not make the coordinates positive. */
1990 #define DEFAULT_ROWS 40
1991 #define DEFAULT_COLS 80
1994 x_figure_window_size (f
, parms
)
1998 register Lisp_Object tem0
, tem1
, tem2
;
1999 int height
, width
, left
, top
;
2000 register int geometry
;
2001 long window_prompting
= 0;
2003 /* Default values if we fall through.
2004 Actually, if that happens we should get
2005 window manager prompting. */
2006 f
->width
= DEFAULT_COLS
;
2007 f
->height
= DEFAULT_ROWS
;
2008 /* Window managers expect that if program-specified
2009 positions are not (0,0), they're intentional, not defaults. */
2010 f
->display
.x
->top_pos
= 0;
2011 f
->display
.x
->left_pos
= 0;
2013 tem0
= x_get_arg (parms
, Qheight
, 0, 0, number
);
2014 tem1
= x_get_arg (parms
, Qwidth
, 0, 0, number
);
2015 tem2
= x_get_arg (parms
, Quser_size
, 0, 0, number
);
2016 if (! EQ (tem0
, Qunbound
) || ! EQ (tem1
, Qunbound
))
2018 if (!EQ (tem0
, Qunbound
))
2020 CHECK_NUMBER (tem0
, 0);
2021 f
->height
= XINT (tem0
);
2023 if (!EQ (tem1
, Qunbound
))
2025 CHECK_NUMBER (tem1
, 0);
2026 f
->width
= XINT (tem1
);
2028 if (!NILP (tem2
) && !EQ (tem2
, Qunbound
))
2029 window_prompting
|= USSize
;
2031 window_prompting
|= PSize
;
2034 f
->display
.x
->vertical_scroll_bar_extra
2035 = (!FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
2037 : FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) > 0
2038 ? FRAME_SCROLL_BAR_PIXEL_WIDTH (f
)
2039 : (FRAME_SCROLL_BAR_COLS (f
) * FONT_WIDTH (f
->display
.x
->font
)));
2040 f
->display
.x
->pixel_width
= CHAR_TO_PIXEL_WIDTH (f
, f
->width
);
2041 f
->display
.x
->pixel_height
= CHAR_TO_PIXEL_HEIGHT (f
, f
->height
);
2043 tem0
= x_get_arg (parms
, Qtop
, 0, 0, number
);
2044 tem1
= x_get_arg (parms
, Qleft
, 0, 0, number
);
2045 tem2
= x_get_arg (parms
, Quser_position
, 0, 0, number
);
2046 if (! EQ (tem0
, Qunbound
) || ! EQ (tem1
, Qunbound
))
2048 if (EQ (tem0
, Qminus
))
2050 f
->display
.x
->top_pos
= 0;
2051 window_prompting
|= YNegative
;
2053 else if (CONSP (tem0
) && EQ (XCONS (tem0
)->car
, Qminus
)
2054 && CONSP (XCONS (tem0
)->cdr
)
2055 && INTEGERP (XCONS (XCONS (tem0
)->cdr
)->car
))
2057 f
->display
.x
->top_pos
= - XINT (XCONS (XCONS (tem0
)->cdr
)->car
);
2058 window_prompting
|= YNegative
;
2060 else if (CONSP (tem0
) && EQ (XCONS (tem0
)->car
, Qplus
)
2061 && CONSP (XCONS (tem0
)->cdr
)
2062 && INTEGERP (XCONS (XCONS (tem0
)->cdr
)->car
))
2064 f
->display
.x
->top_pos
= XINT (XCONS (XCONS (tem0
)->cdr
)->car
);
2066 else if (EQ (tem0
, Qunbound
))
2067 f
->display
.x
->top_pos
= 0;
2070 CHECK_NUMBER (tem0
, 0);
2071 f
->display
.x
->top_pos
= XINT (tem0
);
2072 if (f
->display
.x
->top_pos
< 0)
2073 window_prompting
|= YNegative
;
2076 if (EQ (tem1
, Qminus
))
2078 f
->display
.x
->left_pos
= 0;
2079 window_prompting
|= XNegative
;
2081 else if (CONSP (tem1
) && EQ (XCONS (tem1
)->car
, Qminus
)
2082 && CONSP (XCONS (tem1
)->cdr
)
2083 && INTEGERP (XCONS (XCONS (tem1
)->cdr
)->car
))
2085 f
->display
.x
->left_pos
= - XINT (XCONS (XCONS (tem1
)->cdr
)->car
);
2086 window_prompting
|= XNegative
;
2088 else if (CONSP (tem1
) && EQ (XCONS (tem1
)->car
, Qplus
)
2089 && CONSP (XCONS (tem1
)->cdr
)
2090 && INTEGERP (XCONS (XCONS (tem1
)->cdr
)->car
))
2092 f
->display
.x
->left_pos
= XINT (XCONS (XCONS (tem1
)->cdr
)->car
);
2094 else if (EQ (tem1
, Qunbound
))
2095 f
->display
.x
->left_pos
= 0;
2098 CHECK_NUMBER (tem1
, 0);
2099 f
->display
.x
->left_pos
= XINT (tem1
);
2100 if (f
->display
.x
->left_pos
< 0)
2101 window_prompting
|= XNegative
;
2105 window_prompting
|= USPosition
;
2107 window_prompting
|= PPosition
;
2110 return window_prompting
;
2113 #if !defined (HAVE_X11R4) && !defined (HAVE_XSETWMPROTOCOLS)
2116 XSetWMProtocols (dpy
, w
, protocols
, count
)
2123 prop
= XInternAtom (dpy
, "WM_PROTOCOLS", False
);
2124 if (prop
== None
) return False
;
2125 XChangeProperty (dpy
, w
, prop
, XA_ATOM
, 32, PropModeReplace
,
2126 (unsigned char *) protocols
, count
);
2129 #endif /* not HAVE_X11R4 && not HAVE_XSETWMPROTOCOLS */
2131 #ifdef USE_X_TOOLKIT
2133 /* If the WM_PROTOCOLS property does not already contain WM_TAKE_FOCUS,
2134 WM_DELETE_WINDOW, and WM_SAVE_YOURSELF, then add them. (They may
2135 already be present because of the toolkit (Motif adds some of them,
2136 for example, but Xt doesn't). */
2139 hack_wm_protocols (f
, widget
)
2143 Display
*dpy
= XtDisplay (widget
);
2144 Window w
= XtWindow (widget
);
2145 int need_delete
= 1;
2151 Atom type
, *atoms
= 0;
2153 unsigned long nitems
= 0;
2154 unsigned long bytes_after
;
2156 if (Success
== XGetWindowProperty (dpy
, w
,
2157 FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_protocols
,
2158 0, 100, False
, XA_ATOM
,
2159 &type
, &format
, &nitems
, &bytes_after
,
2160 (unsigned char **) &atoms
)
2161 && format
== 32 && type
== XA_ATOM
)
2165 if (atoms
[nitems
] == FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_delete_window
)
2167 else if (atoms
[nitems
] == FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_take_focus
)
2169 else if (atoms
[nitems
] == FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_save_yourself
)
2172 if (atoms
) XFree ((char *) atoms
);
2178 props
[count
++] = FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_delete_window
;
2180 props
[count
++] = FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_take_focus
;
2182 props
[count
++] = FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_save_yourself
;
2184 XChangeProperty (dpy
, w
, FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_protocols
,
2185 XA_ATOM
, 32, PropModeAppend
,
2186 (unsigned char *) props
, count
);
2192 #ifdef USE_X_TOOLKIT
2194 /* Create and set up the X widget for frame F. */
2197 x_window (f
, window_prompting
, minibuffer_only
)
2199 long window_prompting
;
2200 int minibuffer_only
;
2202 XClassHint class_hints
;
2203 XSetWindowAttributes attributes
;
2204 unsigned long attribute_mask
;
2206 Widget shell_widget
;
2208 Widget frame_widget
;
2215 if (STRINGP (f
->name
))
2216 name
= (char*) XSTRING (f
->name
)->data
;
2221 XtSetArg (al
[ac
], XtNallowShellResize
, 1); ac
++;
2222 XtSetArg (al
[ac
], XtNinput
, 1); ac
++;
2223 shell_widget
= XtCreatePopupShell ("shell",
2224 topLevelShellWidgetClass
,
2225 Xt_app_shell
, al
, ac
);
2227 f
->display
.x
->widget
= shell_widget
;
2228 /* maybe_set_screen_title_format (shell_widget); */
2230 pane_widget
= lw_create_widget ("main", "pane", widget_id_tick
++,
2231 (widget_value
*) NULL
,
2232 shell_widget
, False
,
2235 (lw_callback
) NULL
);
2237 f
->display
.x
->column_widget
= pane_widget
;
2239 if (!minibuffer_only
&& FRAME_EXTERNAL_MENU_BAR (f
))
2240 initialize_frame_menubar (f
);
2242 /* mappedWhenManaged to false tells to the paned window to not map/unmap
2243 the emacs screen when changing menubar. This reduces flickering. */
2246 XtSetArg (al
[ac
], XtNmappedWhenManaged
, 0); ac
++;
2247 XtSetArg (al
[ac
], XtNshowGrip
, 0); ac
++;
2248 XtSetArg (al
[ac
], XtNallowResize
, 1); ac
++;
2249 XtSetArg (al
[ac
], XtNresizeToPreferred
, 1); ac
++;
2250 XtSetArg (al
[ac
], XtNemacsFrame
, f
); ac
++;
2251 frame_widget
= XtCreateWidget (name
,
2253 pane_widget
, al
, ac
);
2254 lw_set_main_areas (pane_widget
, f
->display
.x
->menubar_widget
, frame_widget
);
2256 f
->display
.x
->edit_widget
= frame_widget
;
2258 if (f
->display
.x
->menubar_widget
)
2259 XtManageChild (f
->display
.x
->menubar_widget
);
2260 XtManageChild (frame_widget
);
2262 /* Do some needed geometry management. */
2265 char *tem
, shell_position
[32];
2269 = (f
->display
.x
->menubar_widget
2270 ? (f
->display
.x
->menubar_widget
->core
.height
2271 + f
->display
.x
->menubar_widget
->core
.border_width
)
2274 if (FRAME_EXTERNAL_MENU_BAR (f
))
2277 XtVaGetValues (pane_widget
, XtNinternalBorderWidth
, &ibw
, NULL
);
2278 menubar_size
+= ibw
;
2281 if (window_prompting
& USPosition
)
2283 int left
= f
->display
.x
->left_pos
;
2284 int xneg
= window_prompting
& XNegative
;
2285 int top
= f
->display
.x
->top_pos
;
2286 int yneg
= window_prompting
& YNegative
;
2291 sprintf (shell_position
, "=%dx%d%c%d%c%d", PIXEL_WIDTH (f
),
2292 PIXEL_HEIGHT (f
) + menubar_size
,
2293 (xneg
? '-' : '+'), left
,
2294 (yneg
? '-' : '+'), top
);
2297 sprintf (shell_position
, "=%dx%d", PIXEL_WIDTH (f
),
2298 PIXEL_HEIGHT (f
) + menubar_size
);
2299 len
= strlen (shell_position
) + 1;
2300 tem
= (char *) xmalloc (len
);
2301 strncpy (tem
, shell_position
, len
);
2302 XtSetArg (al
[ac
], XtNgeometry
, tem
); ac
++;
2303 XtSetValues (shell_widget
, al
, ac
);
2306 x_calc_absolute_position (f
);
2308 XtManageChild (pane_widget
);
2309 XtRealizeWidget (shell_widget
);
2311 FRAME_X_WINDOW (f
) = XtWindow (frame_widget
);
2313 validate_x_resource_name ();
2314 class_hints
.res_name
= (char *) XSTRING (Vx_resource_name
)->data
;
2315 class_hints
.res_class
= EMACS_CLASS
;
2316 XSetClassHint (FRAME_X_DISPLAY (f
), XtWindow (shell_widget
), &class_hints
);
2318 f
->display
.x
->wm_hints
.input
= True
;
2319 f
->display
.x
->wm_hints
.flags
|= InputHint
;
2320 XSetWMHints (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2321 &f
->display
.x
->wm_hints
);
2323 hack_wm_protocols (shell_widget
);
2326 XtAddEventHandler (shell_widget
, 0, True
, _XEditResCheckMessages
, 0);
2329 /* Do a stupid property change to force the server to generate a
2330 propertyNotify event so that the event_stream server timestamp will
2331 be initialized to something relevant to the time we created the window.
2333 XChangeProperty (XtDisplay (frame_widget
), XtWindow (frame_widget
),
2334 FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_protocols
,
2335 XA_ATOM
, 32, PropModeAppend
,
2336 (unsigned char*) NULL
, 0);
2338 /* Make all the standard events reach the Emacs frame. */
2339 attributes
.event_mask
= STANDARD_EVENT_SET
;
2340 attribute_mask
= CWEventMask
;
2341 XChangeWindowAttributes (XtDisplay (shell_widget
), XtWindow (shell_widget
),
2342 attribute_mask
, &attributes
);
2344 XtMapWidget (frame_widget
);
2346 /* x_set_name normally ignores requests to set the name if the
2347 requested name is the same as the current name. This is the one
2348 place where that assumption isn't correct; f->name is set, but
2349 the X server hasn't been told. */
2352 int explicit = f
->explicit_name
;
2354 f
->explicit_name
= 0;
2357 x_set_name (f
, name
, explicit);
2360 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2361 f
->display
.x
->text_cursor
);
2365 if (FRAME_X_WINDOW (f
) == 0)
2366 error ("Unable to create window");
2369 #else /* not USE_X_TOOLKIT */
2371 /* Create and set up the X window for frame F. */
2377 XClassHint class_hints
;
2378 XSetWindowAttributes attributes
;
2379 unsigned long attribute_mask
;
2381 attributes
.background_pixel
= f
->display
.x
->background_pixel
;
2382 attributes
.border_pixel
= f
->display
.x
->border_pixel
;
2383 attributes
.bit_gravity
= StaticGravity
;
2384 attributes
.backing_store
= NotUseful
;
2385 attributes
.save_under
= True
;
2386 attributes
.event_mask
= STANDARD_EVENT_SET
;
2387 attribute_mask
= (CWBackPixel
| CWBorderPixel
| CWBitGravity
2389 | CWBackingStore
| CWSaveUnder
2395 = XCreateWindow (FRAME_X_DISPLAY (f
),
2396 FRAME_X_DISPLAY_INFO (f
)->root_window
,
2397 f
->display
.x
->left_pos
,
2398 f
->display
.x
->top_pos
,
2399 PIXEL_WIDTH (f
), PIXEL_HEIGHT (f
),
2400 f
->display
.x
->border_width
,
2401 CopyFromParent
, /* depth */
2402 InputOutput
, /* class */
2403 FRAME_X_DISPLAY_INFO (f
)->visual
,
2404 attribute_mask
, &attributes
);
2406 validate_x_resource_name ();
2407 class_hints
.res_name
= (char *) XSTRING (Vx_resource_name
)->data
;
2408 class_hints
.res_class
= EMACS_CLASS
;
2409 XSetClassHint (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), &class_hints
);
2411 /* This indicates that we use the "Passive Input" input model.
2412 Unless we do this, we don't get the Focus{In,Out} events that we
2413 need to draw the cursor correctly. Accursed bureaucrats.
2414 XWhipsAndChains (FRAME_X_DISPLAY (f), IronMaiden, &TheRack); */
2416 f
->display
.x
->wm_hints
.input
= True
;
2417 f
->display
.x
->wm_hints
.flags
|= InputHint
;
2418 XSetWMHints (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2419 &f
->display
.x
->wm_hints
);
2421 /* Request "save yourself" and "delete window" commands from wm. */
2424 protocols
[0] = FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_delete_window
;
2425 protocols
[1] = FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_save_yourself
;
2426 XSetWMProtocols (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), protocols
, 2);
2429 /* x_set_name normally ignores requests to set the name if the
2430 requested name is the same as the current name. This is the one
2431 place where that assumption isn't correct; f->name is set, but
2432 the X server hasn't been told. */
2435 int explicit = f
->explicit_name
;
2437 f
->explicit_name
= 0;
2440 x_set_name (f
, name
, explicit);
2443 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2444 f
->display
.x
->text_cursor
);
2448 if (FRAME_X_WINDOW (f
) == 0)
2449 error ("Unable to create window");
2452 #endif /* not USE_X_TOOLKIT */
2454 /* Handle the icon stuff for this window. Perhaps later we might
2455 want an x_set_icon_position which can be called interactively as
2463 Lisp_Object icon_x
, icon_y
;
2465 /* Set the position of the icon. Note that twm groups all
2466 icons in an icon window. */
2467 icon_x
= x_get_arg (parms
, Qicon_left
, 0, 0, number
);
2468 icon_y
= x_get_arg (parms
, Qicon_top
, 0, 0, number
);
2469 if (!EQ (icon_x
, Qunbound
) && !EQ (icon_y
, Qunbound
))
2471 CHECK_NUMBER (icon_x
, 0);
2472 CHECK_NUMBER (icon_y
, 0);
2474 else if (!EQ (icon_x
, Qunbound
) || !EQ (icon_y
, Qunbound
))
2475 error ("Both left and top icon corners of icon must be specified");
2479 if (! EQ (icon_x
, Qunbound
))
2480 x_wm_set_icon_position (f
, XINT (icon_x
), XINT (icon_y
));
2482 /* Start up iconic or window? */
2483 x_wm_set_window_state
2484 (f
, (EQ (x_get_arg (parms
, Qvisibility
, 0, 0, symbol
), Qicon
)
2491 /* Make the GC's needed for this window, setting the
2492 background, border and mouse colors; also create the
2493 mouse cursor and the gray border tile. */
2495 static char cursor_bits
[] =
2497 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2498 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2499 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2500 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
2507 XGCValues gc_values
;
2513 /* Create the GC's of this frame.
2514 Note that many default values are used. */
2517 gc_values
.font
= f
->display
.x
->font
->fid
;
2518 gc_values
.foreground
= f
->display
.x
->foreground_pixel
;
2519 gc_values
.background
= f
->display
.x
->background_pixel
;
2520 gc_values
.line_width
= 0; /* Means 1 using fast algorithm. */
2521 f
->display
.x
->normal_gc
= XCreateGC (FRAME_X_DISPLAY (f
),
2523 GCLineWidth
| GCFont
2524 | GCForeground
| GCBackground
,
2527 /* Reverse video style. */
2528 gc_values
.foreground
= f
->display
.x
->background_pixel
;
2529 gc_values
.background
= f
->display
.x
->foreground_pixel
;
2530 f
->display
.x
->reverse_gc
= XCreateGC (FRAME_X_DISPLAY (f
),
2532 GCFont
| GCForeground
| GCBackground
2536 /* Cursor has cursor-color background, background-color foreground. */
2537 gc_values
.foreground
= f
->display
.x
->background_pixel
;
2538 gc_values
.background
= f
->display
.x
->cursor_pixel
;
2539 gc_values
.fill_style
= FillOpaqueStippled
;
2541 = XCreateBitmapFromData (FRAME_X_DISPLAY (f
),
2542 FRAME_X_DISPLAY_INFO (f
)->root_window
,
2543 cursor_bits
, 16, 16);
2544 f
->display
.x
->cursor_gc
2545 = XCreateGC (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2546 (GCFont
| GCForeground
| GCBackground
2547 | GCFillStyle
| GCStipple
| GCLineWidth
),
2550 /* Create the gray border tile used when the pointer is not in
2551 the frame. Since this depends on the frame's pixel values,
2552 this must be done on a per-frame basis. */
2553 f
->display
.x
->border_tile
2554 = (XCreatePixmapFromBitmapData
2555 (FRAME_X_DISPLAY (f
), FRAME_X_DISPLAY_INFO (f
)->root_window
,
2556 gray_bits
, gray_width
, gray_height
,
2557 f
->display
.x
->foreground_pixel
,
2558 f
->display
.x
->background_pixel
,
2559 DefaultDepth (FRAME_X_DISPLAY (f
),
2560 XScreenNumberOfScreen (FRAME_X_SCREEN (f
)))));
2565 DEFUN ("x-create-frame", Fx_create_frame
, Sx_create_frame
,
2567 "Make a new X window, which is called a \"frame\" in Emacs terms.\n\
2568 Return an Emacs frame object representing the X window.\n\
2569 ALIST is an alist of frame parameters.\n\
2570 If the parameters specify that the frame should not have a minibuffer,\n\
2571 and do not specify a specific minibuffer window to use,\n\
2572 then `default-minibuffer-frame' must be a frame whose minibuffer can\n\
2573 be shared by the new frame.")
2578 Lisp_Object frame
, tem
;
2580 int minibuffer_only
= 0;
2581 long window_prompting
= 0;
2583 int count
= specpdl_ptr
- specpdl
;
2584 struct gcpro gcpro1
;
2585 Lisp_Object display
;
2586 struct x_display_info
*dpyinfo
;
2590 display
= x_get_arg (parms
, Qdisplay
, 0, 0, 0);
2591 if (EQ (display
, Qunbound
))
2593 dpyinfo
= check_x_display_info (display
);
2595 name
= x_get_arg (parms
, Qname
, "title", "Title", string
);
2597 && ! EQ (name
, Qunbound
)
2599 error ("x-create-frame: name parameter must be a string");
2601 tem
= x_get_arg (parms
, Qminibuffer
, 0, 0, symbol
);
2602 if (EQ (tem
, Qnone
) || NILP (tem
))
2603 f
= make_frame_without_minibuffer (Qnil
);
2604 else if (EQ (tem
, Qonly
))
2606 f
= make_minibuffer_frame ();
2607 minibuffer_only
= 1;
2609 else if (WINDOWP (tem
))
2610 f
= make_frame_without_minibuffer (tem
);
2614 /* Note that X Windows does support scroll bars. */
2615 FRAME_CAN_HAVE_SCROLL_BARS (f
) = 1;
2617 /* Set the name; the functions to which we pass f expect the name to
2619 if (EQ (name
, Qunbound
) || NILP (name
))
2621 f
->name
= build_string (x_id_name
);
2622 f
->explicit_name
= 0;
2627 f
->explicit_name
= 1;
2628 /* use the frame's title when getting resources for this frame. */
2629 specbind (Qx_resource_name
, name
);
2632 XSETFRAME (frame
, f
);
2635 f
->output_method
= output_x_window
;
2636 f
->display
.x
= (struct x_display
*) xmalloc (sizeof (struct x_display
));
2637 bzero (f
->display
.x
, sizeof (struct x_display
));
2638 f
->display
.x
->icon_bitmap
= -1;
2640 FRAME_X_DISPLAY_INFO (f
) = dpyinfo
;
2641 FRAME_X_DISPLAY_INFO (f
)->reference_count
++;
2643 /* Note that the frame has no physical cursor right now. */
2644 f
->phys_cursor_x
= -1;
2646 /* Extract the window parameters from the supplied values
2647 that are needed to determine window geometry. */
2651 font
= x_get_arg (parms
, Qfont
, "font", "Font", string
);
2653 /* First, try whatever font the caller has specified. */
2655 font
= x_new_font (f
, XSTRING (font
)->data
);
2656 /* Try out a font which we hope has bold and italic variations. */
2657 if (!STRINGP (font
))
2658 font
= x_new_font (f
, "-misc-fixed-medium-r-normal-*-*-140-*-*-c-*-iso8859-1");
2659 if (! STRINGP (font
))
2660 font
= x_new_font (f
, "-*-*-medium-r-normal-*-*-140-*-*-c-*-iso8859-1");
2661 if (! STRINGP (font
))
2662 /* This was formerly the first thing tried, but it finds too many fonts
2663 and takes too long. */
2664 font
= x_new_font (f
, "-*-*-medium-r-*-*-*-*-*-*-c-*-iso8859-1");
2665 /* If those didn't work, look for something which will at least work. */
2666 if (! STRINGP (font
))
2667 font
= x_new_font (f
, "-*-fixed-*-*-*-*-*-140-*-*-c-*-iso8859-1");
2669 if (! STRINGP (font
))
2670 font
= build_string ("fixed");
2672 x_default_parameter (f
, parms
, Qfont
, font
,
2673 "font", "Font", string
);
2676 x_default_parameter (f
, parms
, Qborder_width
, make_number (2),
2677 "borderwidth", "BorderWidth", number
);
2678 /* This defaults to 2 in order to match xterm. We recognize either
2679 internalBorderWidth or internalBorder (which is what xterm calls
2681 if (NILP (Fassq (Qinternal_border_width
, parms
)))
2685 value
= x_get_arg (parms
, Qinternal_border_width
,
2686 "internalBorder", "BorderWidth", number
);
2687 if (! EQ (value
, Qunbound
))
2688 parms
= Fcons (Fcons (Qinternal_border_width
, value
),
2691 x_default_parameter (f
, parms
, Qinternal_border_width
, make_number (2),
2692 "internalBorderWidth", "BorderWidth", number
);
2693 x_default_parameter (f
, parms
, Qvertical_scroll_bars
, Qt
,
2694 "verticalScrollBars", "ScrollBars", boolean
);
2696 /* Also do the stuff which must be set before the window exists. */
2697 x_default_parameter (f
, parms
, Qforeground_color
, build_string ("black"),
2698 "foreground", "Foreground", string
);
2699 x_default_parameter (f
, parms
, Qbackground_color
, build_string ("white"),
2700 "background", "Background", string
);
2701 x_default_parameter (f
, parms
, Qmouse_color
, build_string ("black"),
2702 "pointerColor", "Foreground", string
);
2703 x_default_parameter (f
, parms
, Qcursor_color
, build_string ("black"),
2704 "cursorColor", "Foreground", string
);
2705 x_default_parameter (f
, parms
, Qborder_color
, build_string ("black"),
2706 "borderColor", "BorderColor", string
);
2708 x_default_parameter (f
, parms
, Qmenu_bar_lines
, make_number (1),
2709 "menuBar", "MenuBar", number
);
2710 x_default_parameter (f
, parms
, Qscroll_bar_width
, Qnil
,
2711 "scrollBarWidth", "ScrollBarWidth", number
);
2713 f
->display
.x
->parent_desc
= FRAME_X_DISPLAY_INFO (f
)->root_window
;
2714 window_prompting
= x_figure_window_size (f
, parms
);
2716 if (window_prompting
& XNegative
)
2718 if (window_prompting
& YNegative
)
2719 f
->display
.x
->win_gravity
= SouthEastGravity
;
2721 f
->display
.x
->win_gravity
= NorthEastGravity
;
2725 if (window_prompting
& YNegative
)
2726 f
->display
.x
->win_gravity
= SouthWestGravity
;
2728 f
->display
.x
->win_gravity
= NorthWestGravity
;
2731 f
->display
.x
->size_hint_flags
= window_prompting
;
2733 #ifdef USE_X_TOOLKIT
2734 x_window (f
, window_prompting
, minibuffer_only
);
2740 init_frame_faces (f
);
2742 /* We need to do this after creating the X window, so that the
2743 icon-creation functions can say whose icon they're describing. */
2744 x_default_parameter (f
, parms
, Qicon_type
, Qnil
,
2745 "bitmapIcon", "BitmapIcon", symbol
);
2747 x_default_parameter (f
, parms
, Qauto_raise
, Qnil
,
2748 "autoRaise", "AutoRaiseLower", boolean
);
2749 x_default_parameter (f
, parms
, Qauto_lower
, Qnil
,
2750 "autoLower", "AutoRaiseLower", boolean
);
2751 x_default_parameter (f
, parms
, Qcursor_type
, Qbox
,
2752 "cursorType", "CursorType", symbol
);
2754 /* Dimensions, especially f->height, must be done via change_frame_size.
2755 Change will not be effected unless different from the current
2759 f
->height
= f
->width
= 0;
2760 change_frame_size (f
, height
, width
, 1, 0);
2762 /* With the toolkit, the geometry management is done in x_window. */
2763 #ifndef USE_X_TOOLKIT
2765 x_wm_set_size_hint (f
, window_prompting
, 0);
2767 #endif /* USE_X_TOOLKIT */
2769 tem
= x_get_arg (parms
, Qunsplittable
, 0, 0, boolean
);
2770 f
->no_split
= minibuffer_only
|| EQ (tem
, Qt
);
2774 /* It is now ok to make the frame official
2775 even if we get an error below.
2776 And the frame needs to be on Vframe_list
2777 or making it visible won't work. */
2778 Vframe_list
= Fcons (frame
, Vframe_list
);
2780 /* Make the window appear on the frame and enable display,
2781 unless the caller says not to. */
2783 Lisp_Object visibility
;
2785 visibility
= x_get_arg (parms
, Qvisibility
, 0, 0, symbol
);
2786 if (EQ (visibility
, Qunbound
))
2789 if (EQ (visibility
, Qicon
))
2790 x_iconify_frame (f
);
2791 else if (! NILP (visibility
))
2792 x_make_frame_visible (f
);
2794 /* Must have been Qnil. */
2798 return unbind_to (count
, frame
);
2802 x_get_focus_frame ()
2805 if (! x_focus_frame
)
2808 XSETFRAME (xfocus
, x_focus_frame
);
2812 DEFUN ("focus-frame", Ffocus_frame
, Sfocus_frame
, 1, 1, 0,
2813 "Set the focus on FRAME.")
2817 CHECK_LIVE_FRAME (frame
, 0);
2819 if (FRAME_X_P (XFRAME (frame
)))
2822 x_focus_on_frame (XFRAME (frame
));
2830 DEFUN ("unfocus-frame", Funfocus_frame
, Sunfocus_frame
, 0, 0, 0,
2831 "If a frame has been focused, release it.")
2837 x_unfocus_frame (x_focus_frame
);
2844 DEFUN ("x-list-fonts", Fx_list_fonts
, Sx_list_fonts
, 1, 3, 0,
2845 "Return a list of the names of available fonts matching PATTERN.\n\
2846 If optional arguments FACE and FRAME are specified, return only fonts\n\
2847 the same size as FACE on FRAME.\n\
2849 PATTERN is a string, perhaps with wildcard characters;\n\
2850 the * character matches any substring, and\n\
2851 the ? character matches any single character.\n\
2852 PATTERN is case-insensitive.\n\
2853 FACE is a face name - a symbol.\n\
2855 The return value is a list of strings, suitable as arguments to\n\
2858 Fonts Emacs can't use (i.e. proportional fonts) may or may not be excluded\n\
2859 even if they match PATTERN and FACE.")
2860 (pattern
, face
, frame
)
2861 Lisp_Object pattern
, face
, frame
;
2866 XFontStruct
*size_ref
;
2871 CHECK_STRING (pattern
, 0);
2873 CHECK_SYMBOL (face
, 1);
2875 f
= check_x_frame (frame
);
2877 /* Determine the width standard for comparison with the fonts we find. */
2885 /* Don't die if we get called with a terminal frame. */
2886 if (! FRAME_X_P (f
))
2887 error ("non-X frame used in `x-list-fonts'");
2889 face_id
= face_name_id_number (f
, face
);
2891 if (face_id
< 0 || face_id
>= FRAME_N_PARAM_FACES (f
)
2892 || FRAME_PARAM_FACES (f
) [face_id
] == 0)
2893 size_ref
= f
->display
.x
->font
;
2896 size_ref
= FRAME_PARAM_FACES (f
) [face_id
]->font
;
2897 if (size_ref
== (XFontStruct
*) (~0))
2898 size_ref
= f
->display
.x
->font
;
2902 /* See if we cached the result for this particular query. */
2903 list
= Fassoc (pattern
, FRAME_X_DISPLAY_INFO (f
)->font_list_cache
);
2905 /* We have info in the cache for this PATTERN. */
2908 Lisp_Object tem
, newlist
;
2910 /* We have info about this pattern. */
2911 list
= XCONS (list
)->cdr
;
2918 /* Filter the cached info and return just the fonts that match FACE. */
2920 for (tem
= list
; CONSP (tem
); tem
= XCONS (tem
)->cdr
)
2922 XFontStruct
*thisinfo
;
2924 thisinfo
= XLoadQueryFont (FRAME_X_DISPLAY (f
),
2925 XSTRING (XCONS (tem
)->car
)->data
);
2927 if (thisinfo
&& same_size_fonts (thisinfo
, size_ref
))
2928 newlist
= Fcons (XCONS (tem
)->car
, newlist
);
2930 XFreeFont (FRAME_X_DISPLAY (f
), thisinfo
);
2940 /* Solaris 2.3 has a bug in XListFontsWithInfo. */
2941 #ifdef BROKEN_XLISTFONTSWITHINFO
2942 names
= XListFonts (FRAME_X_DISPLAY (f
),
2943 XSTRING (pattern
)->data
,
2944 2000, /* maxnames */
2945 &num_fonts
); /* count_return */
2947 names
= XListFontsWithInfo (FRAME_X_DISPLAY (f
),
2948 XSTRING (pattern
)->data
,
2949 2000, /* maxnames */
2950 &num_fonts
, /* count_return */
2951 &info
); /* info_return */
2960 Lisp_Object full_list
;
2962 /* Make a list of all the fonts we got back.
2963 Store that in the font cache for the display. */
2965 for (i
= 0; i
< num_fonts
; i
++)
2966 full_list
= Fcons (build_string (names
[i
]), full_list
);
2967 FRAME_X_DISPLAY_INFO (f
)->font_list_cache
2968 = Fcons (Fcons (pattern
, full_list
),
2969 FRAME_X_DISPLAY_INFO (f
)->font_list_cache
);
2971 /* Make a list of the fonts that have the right width. */
2973 for (i
= 0; i
< num_fonts
; i
++)
2975 XFontStruct
*thisinfo
;
2977 #ifdef BROKEN_XLISTFONTSWITHINFO
2979 thisinfo
= XLoadQueryFont (FRAME_X_DISPLAY (f
), names
[i
]);
2982 thisinfo
= &info
[i
];
2984 if (thisinfo
&& (! size_ref
2985 || same_size_fonts (thisinfo
, size_ref
)))
2986 list
= Fcons (build_string (names
[i
]), list
);
2988 list
= Fnreverse (list
);
2991 #ifdef BROKEN_XLISTFONTSWITHINFO
2992 XFreeFontNames (names
);
2994 XFreeFontInfo (names
, info
, num_fonts
);
3003 DEFUN ("x-color-defined-p", Fx_color_defined_p
, Sx_color_defined_p
, 1, 2, 0,
3004 "Return non-nil color COLOR is supported on frame FRAME.")
3006 Lisp_Object color
, frame
;
3009 FRAME_PTR f
= check_x_frame (frame
);
3011 CHECK_STRING (color
, 1);
3013 if (defined_color (f
, XSTRING (color
)->data
, &foo
, 0))
3019 DEFUN ("x-color-values", Fx_color_values
, Sx_color_values
, 1, 2, 0,
3020 "Return a description of the color named COLOR on frame FRAME.\n\
3021 The value is a list of integer RGB values--(RED GREEN BLUE).\n\
3022 These values appear to range from 0 to 65280; white is (65280 65280 65280).")
3024 Lisp_Object color
, frame
;
3027 FRAME_PTR f
= check_x_frame (frame
);
3029 CHECK_STRING (color
, 1);
3031 if (defined_color (f
, XSTRING (color
)->data
, &foo
, 0))
3035 rgb
[0] = make_number (foo
.red
);
3036 rgb
[1] = make_number (foo
.green
);
3037 rgb
[2] = make_number (foo
.blue
);
3038 return Flist (3, rgb
);
3044 DEFUN ("x-display-color-p", Fx_display_color_p
, Sx_display_color_p
, 0, 1, 0,
3045 "Return t if the X screen FRAME is on supports color.")
3049 struct x_display_info
*dpyinfo
= check_x_display_info (frame
);
3051 if (dpyinfo
->n_planes
<= 2)
3054 switch (dpyinfo
->visual
->class)
3067 DEFUN ("x-display-grayscale-p", Fx_display_grayscale_p
, Sx_display_grayscale_p
,
3069 "Return t if the X screen FRAME is on supports grayscale.")
3073 struct x_display_info
*dpyinfo
= check_x_display_info (frame
);
3075 if (dpyinfo
->n_planes
<= 2)
3078 return (dpyinfo
->n_planes
> 1
3079 && (dpyinfo
->visual
->class == StaticGray
3080 || dpyinfo
->visual
->class == GrayScale
));
3083 DEFUN ("x-display-pixel-width", Fx_display_pixel_width
, Sx_display_pixel_width
,
3085 "Returns the width in pixels of the display FRAME is on.")
3089 struct x_display_info
*dpyinfo
= check_x_display_info (frame
);
3091 return make_number (dpyinfo
->width
);
3094 DEFUN ("x-display-pixel-height", Fx_display_pixel_height
,
3095 Sx_display_pixel_height
, 0, 1, 0,
3096 "Returns the height in pixels of the display FRAME is on.")
3100 struct x_display_info
*dpyinfo
= check_x_display_info (frame
);
3102 return make_number (dpyinfo
->height
);
3105 DEFUN ("x-display-planes", Fx_display_planes
, Sx_display_planes
,
3107 "Returns the number of bitplanes of the display FRAME is on.")
3111 struct x_display_info
*dpyinfo
= check_x_display_info (frame
);
3113 return make_number (dpyinfo
->n_planes
);
3116 DEFUN ("x-display-color-cells", Fx_display_color_cells
, Sx_display_color_cells
,
3118 "Returns the number of color cells of the display FRAME is on.")
3122 struct x_display_info
*dpyinfo
= check_x_display_info (frame
);
3124 return make_number (DisplayCells (dpyinfo
->display
,
3125 XScreenNumberOfScreen (dpyinfo
->screen
)));
3128 DEFUN ("x-server-max-request-size", Fx_server_max_request_size
,
3129 Sx_server_max_request_size
,
3131 "Returns the maximum request size of the X server FRAME is using.")
3135 struct x_display_info
*dpyinfo
= check_x_display_info (frame
);
3137 return make_number (MAXREQUEST (dpyinfo
->display
));
3140 DEFUN ("x-server-vendor", Fx_server_vendor
, Sx_server_vendor
, 0, 1, 0,
3141 "Returns the vendor ID string of the X server FRAME is on.")
3145 struct x_display_info
*dpyinfo
= check_x_display_info (frame
);
3146 char *vendor
= ServerVendor (dpyinfo
->display
);
3148 if (! vendor
) vendor
= "";
3149 return build_string (vendor
);
3152 DEFUN ("x-server-version", Fx_server_version
, Sx_server_version
, 0, 1, 0,
3153 "Returns the version numbers of the X server in use.\n\
3154 The value is a list of three integers: the major and minor\n\
3155 version numbers of the X Protocol in use, and the vendor-specific release\n\
3156 number. See also the variable `x-server-vendor'.")
3160 struct x_display_info
*dpyinfo
= check_x_display_info (frame
);
3161 Display
*dpy
= dpyinfo
->display
;
3163 return Fcons (make_number (ProtocolVersion (dpy
)),
3164 Fcons (make_number (ProtocolRevision (dpy
)),
3165 Fcons (make_number (VendorRelease (dpy
)), Qnil
)));
3168 DEFUN ("x-display-screens", Fx_display_screens
, Sx_display_screens
, 0, 1, 0,
3169 "Returns the number of screens on the X server FRAME is on.")
3173 struct x_display_info
*dpyinfo
= check_x_display_info (frame
);
3175 return make_number (ScreenCount (dpyinfo
->display
));
3178 DEFUN ("x-display-mm-height", Fx_display_mm_height
, Sx_display_mm_height
, 0, 1, 0,
3179 "Returns the height in millimeters of the X screen FRAME is on.")
3183 struct x_display_info
*dpyinfo
= check_x_display_info (frame
);
3185 return make_number (HeightMMOfScreen (dpyinfo
->screen
));
3188 DEFUN ("x-display-mm-width", Fx_display_mm_width
, Sx_display_mm_width
, 0, 1, 0,
3189 "Returns the width in millimeters of the X screen FRAME is on.")
3193 struct x_display_info
*dpyinfo
= check_x_display_info (frame
);
3195 return make_number (WidthMMOfScreen (dpyinfo
->screen
));
3198 DEFUN ("x-display-backing-store", Fx_display_backing_store
,
3199 Sx_display_backing_store
, 0, 1, 0,
3200 "Returns an indication of whether the X screen FRAME is on does backing store.\n\
3201 The value may be `always', `when-mapped', or `not-useful'.")
3205 struct x_display_info
*dpyinfo
= check_x_display_info (frame
);
3207 switch (DoesBackingStore (dpyinfo
->screen
))
3210 return intern ("always");
3213 return intern ("when-mapped");
3216 return intern ("not-useful");
3219 error ("Strange value for BackingStore parameter of screen");
3223 DEFUN ("x-display-visual-class", Fx_display_visual_class
,
3224 Sx_display_visual_class
, 0, 1, 0,
3225 "Returns the visual class of the display FRAME is on.\n\
3226 The value is one of the symbols `static-gray', `gray-scale',\n\
3227 `static-color', `pseudo-color', `true-color', or `direct-color'.")
3231 struct x_display_info
*dpyinfo
= check_x_display_info (frame
);
3233 switch (dpyinfo
->visual
->class)
3235 case StaticGray
: return (intern ("static-gray"));
3236 case GrayScale
: return (intern ("gray-scale"));
3237 case StaticColor
: return (intern ("static-color"));
3238 case PseudoColor
: return (intern ("pseudo-color"));
3239 case TrueColor
: return (intern ("true-color"));
3240 case DirectColor
: return (intern ("direct-color"));
3242 error ("Display has an unknown visual class");
3246 DEFUN ("x-display-save-under", Fx_display_save_under
,
3247 Sx_display_save_under
, 0, 1, 0,
3248 "Returns t if the X screen FRAME is on supports the save-under feature.")
3252 struct x_display_info
*dpyinfo
= check_x_display_info (frame
);
3254 if (DoesSaveUnders (dpyinfo
->screen
) == True
)
3262 register struct frame
*f
;
3264 return PIXEL_WIDTH (f
);
3269 register struct frame
*f
;
3271 return PIXEL_HEIGHT (f
);
3276 register struct frame
*f
;
3278 return FONT_WIDTH (f
->display
.x
->font
);
3283 register struct frame
*f
;
3285 return f
->display
.x
->line_height
;
3289 x_screen_planes (frame
)
3292 return FRAME_X_DISPLAY_INFO (XFRAME (frame
))->n_planes
;
3295 #if 0 /* These no longer seem like the right way to do things. */
3297 /* Draw a rectangle on the frame with left top corner including
3298 the character specified by LEFT_CHAR and TOP_CHAR. The rectangle is
3299 CHARS by LINES wide and long and is the color of the cursor. */
3302 x_rectangle (f
, gc
, left_char
, top_char
, chars
, lines
)
3303 register struct frame
*f
;
3305 register int top_char
, left_char
, chars
, lines
;
3309 int left
= (left_char
* FONT_WIDTH (f
->display
.x
->font
)
3310 + f
->display
.x
->internal_border_width
);
3311 int top
= (top_char
* f
->display
.x
->line_height
3312 + f
->display
.x
->internal_border_width
);
3315 width
= FONT_WIDTH (f
->display
.x
->font
) / 2;
3317 width
= FONT_WIDTH (f
->display
.x
->font
) * chars
;
3319 height
= f
->display
.x
->line_height
/ 2;
3321 height
= f
->display
.x
->line_height
* lines
;
3323 XDrawRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3324 gc
, left
, top
, width
, height
);
3327 DEFUN ("x-draw-rectangle", Fx_draw_rectangle
, Sx_draw_rectangle
, 5, 5, 0,
3328 "Draw a rectangle on FRAME between coordinates specified by\n\
3329 numbers X0, Y0, X1, Y1 in the cursor pixel.")
3330 (frame
, X0
, Y0
, X1
, Y1
)
3331 register Lisp_Object frame
, X0
, X1
, Y0
, Y1
;
3333 register int x0
, y0
, x1
, y1
, top
, left
, n_chars
, n_lines
;
3335 CHECK_LIVE_FRAME (frame
, 0);
3336 CHECK_NUMBER (X0
, 0);
3337 CHECK_NUMBER (Y0
, 1);
3338 CHECK_NUMBER (X1
, 2);
3339 CHECK_NUMBER (Y1
, 3);
3349 n_lines
= y1
- y0
+ 1;
3354 n_lines
= y0
- y1
+ 1;
3360 n_chars
= x1
- x0
+ 1;
3365 n_chars
= x0
- x1
+ 1;
3369 x_rectangle (XFRAME (frame
), XFRAME (frame
)->display
.x
->cursor_gc
,
3370 left
, top
, n_chars
, n_lines
);
3376 DEFUN ("x-erase-rectangle", Fx_erase_rectangle
, Sx_erase_rectangle
, 5, 5, 0,
3377 "Draw a rectangle drawn on FRAME between coordinates\n\
3378 X0, Y0, X1, Y1 in the regular background-pixel.")
3379 (frame
, X0
, Y0
, X1
, Y1
)
3380 register Lisp_Object frame
, X0
, Y0
, X1
, Y1
;
3382 register int x0
, y0
, x1
, y1
, top
, left
, n_chars
, n_lines
;
3384 CHECK_LIVE_FRAME (frame
, 0);
3385 CHECK_NUMBER (X0
, 0);
3386 CHECK_NUMBER (Y0
, 1);
3387 CHECK_NUMBER (X1
, 2);
3388 CHECK_NUMBER (Y1
, 3);
3398 n_lines
= y1
- y0
+ 1;
3403 n_lines
= y0
- y1
+ 1;
3409 n_chars
= x1
- x0
+ 1;
3414 n_chars
= x0
- x1
+ 1;
3418 x_rectangle (XFRAME (frame
), XFRAME (frame
)->display
.x
->reverse_gc
,
3419 left
, top
, n_chars
, n_lines
);
3425 /* Draw lines around the text region beginning at the character position
3426 TOP_X, TOP_Y and ending at BOTTOM_X and BOTTOM_Y. GC specifies the
3427 pixel and line characteristics. */
3429 #define line_len(line) (FRAME_CURRENT_GLYPHS (f)->used[(line)])
3432 outline_region (f
, gc
, top_x
, top_y
, bottom_x
, bottom_y
)
3433 register struct frame
*f
;
3435 int top_x
, top_y
, bottom_x
, bottom_y
;
3437 register int ibw
= f
->display
.x
->internal_border_width
;
3438 register int font_w
= FONT_WIDTH (f
->display
.x
->font
);
3439 register int font_h
= f
->display
.x
->line_height
;
3441 int x
= line_len (y
);
3442 XPoint
*pixel_points
3443 = (XPoint
*) alloca (((bottom_y
- top_y
+ 2) * 4) * sizeof (XPoint
));
3444 register XPoint
*this_point
= pixel_points
;
3446 /* Do the horizontal top line/lines */
3449 this_point
->x
= ibw
;
3450 this_point
->y
= ibw
+ (font_h
* top_y
);
3453 this_point
->x
= ibw
+ (font_w
/ 2); /* Half-size for newline chars. */
3455 this_point
->x
= ibw
+ (font_w
* x
);
3456 this_point
->y
= (this_point
- 1)->y
;
3460 this_point
->x
= ibw
;
3461 this_point
->y
= ibw
+ (font_h
* (top_y
+ 1));
3463 this_point
->x
= ibw
+ (font_w
* top_x
);
3464 this_point
->y
= (this_point
- 1)->y
;
3466 this_point
->x
= (this_point
- 1)->x
;
3467 this_point
->y
= ibw
+ (font_h
* top_y
);
3469 this_point
->x
= ibw
+ (font_w
* x
);
3470 this_point
->y
= (this_point
- 1)->y
;
3473 /* Now do the right side. */
3474 while (y
< bottom_y
)
3475 { /* Right vertical edge */
3477 this_point
->x
= (this_point
- 1)->x
;
3478 this_point
->y
= ibw
+ (font_h
* (y
+ 1));
3481 y
++; /* Horizontal connection to next line */
3484 this_point
->x
= ibw
+ (font_w
/ 2);
3486 this_point
->x
= ibw
+ (font_w
* x
);
3488 this_point
->y
= (this_point
- 1)->y
;
3491 /* Now do the bottom and connect to the top left point. */
3492 this_point
->x
= ibw
+ (font_w
* (bottom_x
+ 1));
3495 this_point
->x
= (this_point
- 1)->x
;
3496 this_point
->y
= ibw
+ (font_h
* (bottom_y
+ 1));
3498 this_point
->x
= ibw
;
3499 this_point
->y
= (this_point
- 1)->y
;
3501 this_point
->x
= pixel_points
->x
;
3502 this_point
->y
= pixel_points
->y
;
3504 XDrawLines (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3506 (this_point
- pixel_points
+ 1), CoordModeOrigin
);
3509 DEFUN ("x-contour-region", Fx_contour_region
, Sx_contour_region
, 1, 1, 0,
3510 "Highlight the region between point and the character under the mouse\n\
3513 register Lisp_Object event
;
3515 register int x0
, y0
, x1
, y1
;
3516 register struct frame
*f
= selected_frame
;
3517 register int p1
, p2
;
3519 CHECK_CONS (event
, 0);
3522 x0
= XINT (Fcar (Fcar (event
)));
3523 y0
= XINT (Fcar (Fcdr (Fcar (event
))));
3525 /* If the mouse is past the end of the line, don't that area. */
3526 /* ReWrite this... */
3531 if (y1
> y0
) /* point below mouse */
3532 outline_region (f
, f
->display
.x
->cursor_gc
,
3534 else if (y1
< y0
) /* point above mouse */
3535 outline_region (f
, f
->display
.x
->cursor_gc
,
3537 else /* same line: draw horizontal rectangle */
3540 x_rectangle (f
, f
->display
.x
->cursor_gc
,
3541 x0
, y0
, (x1
- x0
+ 1), 1);
3543 x_rectangle (f
, f
->display
.x
->cursor_gc
,
3544 x1
, y1
, (x0
- x1
+ 1), 1);
3547 XFlush (FRAME_X_DISPLAY (f
));
3553 DEFUN ("x-uncontour-region", Fx_uncontour_region
, Sx_uncontour_region
, 1, 1, 0,
3554 "Erase any highlighting of the region between point and the character\n\
3555 at X, Y on the selected frame.")
3557 register Lisp_Object event
;
3559 register int x0
, y0
, x1
, y1
;
3560 register struct frame
*f
= selected_frame
;
3563 x0
= XINT (Fcar (Fcar (event
)));
3564 y0
= XINT (Fcar (Fcdr (Fcar (event
))));
3568 if (y1
> y0
) /* point below mouse */
3569 outline_region (f
, f
->display
.x
->reverse_gc
,
3571 else if (y1
< y0
) /* point above mouse */
3572 outline_region (f
, f
->display
.x
->reverse_gc
,
3574 else /* same line: draw horizontal rectangle */
3577 x_rectangle (f
, f
->display
.x
->reverse_gc
,
3578 x0
, y0
, (x1
- x0
+ 1), 1);
3580 x_rectangle (f
, f
->display
.x
->reverse_gc
,
3581 x1
, y1
, (x0
- x1
+ 1), 1);
3589 int contour_begin_x
, contour_begin_y
;
3590 int contour_end_x
, contour_end_y
;
3591 int contour_npoints
;
3593 /* Clip the top part of the contour lines down (and including) line Y_POS.
3594 If X_POS is in the middle (rather than at the end) of the line, drop
3595 down a line at that character. */
3598 clip_contour_top (y_pos
, x_pos
)
3600 register XPoint
*begin
= contour_lines
[y_pos
].top_left
;
3601 register XPoint
*end
;
3602 register int npoints
;
3603 register struct display_line
*line
= selected_frame
->phys_lines
[y_pos
+ 1];
3605 if (x_pos
>= line
->len
- 1) /* Draw one, straight horizontal line. */
3607 end
= contour_lines
[y_pos
].top_right
;
3608 npoints
= (end
- begin
+ 1);
3609 XDrawLines (x_current_display
, contour_window
,
3610 contour_erase_gc
, begin_erase
, npoints
, CoordModeOrigin
);
3612 bcopy (end
, begin
+ 1, contour_last_point
- end
+ 1);
3613 contour_last_point
-= (npoints
- 2);
3614 XDrawLines (x_current_display
, contour_window
,
3615 contour_erase_gc
, begin
, 2, CoordModeOrigin
);
3616 XFlush (x_current_display
);
3618 /* Now, update contour_lines structure. */
3623 register XPoint
*p
= begin
+ 1;
3624 end
= contour_lines
[y_pos
].bottom_right
;
3625 npoints
= (end
- begin
+ 1);
3626 XDrawLines (x_current_display
, contour_window
,
3627 contour_erase_gc
, begin_erase
, npoints
, CoordModeOrigin
);
3630 p
->x
= ibw
+ (font_w
* (x_pos
+ 1));
3632 p
->y
= begin
->y
+ font_h
;
3634 bcopy (end
, begin
+ 3, contour_last_point
- end
+ 1);
3635 contour_last_point
-= (npoints
- 5);
3636 XDrawLines (x_current_display
, contour_window
,
3637 contour_erase_gc
, begin
, 4, CoordModeOrigin
);
3638 XFlush (x_current_display
);
3640 /* Now, update contour_lines structure. */
3644 /* Erase the top horizontal lines of the contour, and then extend
3645 the contour upwards. */
3648 extend_contour_top (line
)
3653 clip_contour_bottom (x_pos
, y_pos
)
3659 extend_contour_bottom (x_pos
, y_pos
)
3663 DEFUN ("x-select-region", Fx_select_region
, Sx_select_region
, 1, 1, "e",
3668 register struct frame
*f
= selected_frame
;
3669 register int point_x
= f
->cursor_x
;
3670 register int point_y
= f
->cursor_y
;
3671 register int mouse_below_point
;
3672 register Lisp_Object obj
;
3673 register int x_contour_x
, x_contour_y
;
3675 x_contour_x
= x_mouse_x
;
3676 x_contour_y
= x_mouse_y
;
3677 if (x_contour_y
> point_y
|| (x_contour_y
== point_y
3678 && x_contour_x
> point_x
))
3680 mouse_below_point
= 1;
3681 outline_region (f
, f
->display
.x
->cursor_gc
, point_x
, point_y
,
3682 x_contour_x
, x_contour_y
);
3686 mouse_below_point
= 0;
3687 outline_region (f
, f
->display
.x
->cursor_gc
, x_contour_x
, x_contour_y
,
3693 obj
= read_char (-1, 0, 0, Qnil
, 0);
3697 if (mouse_below_point
)
3699 if (x_mouse_y
<= point_y
) /* Flipped. */
3701 mouse_below_point
= 0;
3703 outline_region (f
, f
->display
.x
->reverse_gc
, point_x
, point_y
,
3704 x_contour_x
, x_contour_y
);
3705 outline_region (f
, f
->display
.x
->cursor_gc
, x_mouse_x
, x_mouse_y
,
3708 else if (x_mouse_y
< x_contour_y
) /* Bottom clipped. */
3710 clip_contour_bottom (x_mouse_y
);
3712 else if (x_mouse_y
> x_contour_y
) /* Bottom extended. */
3714 extend_bottom_contour (x_mouse_y
);
3717 x_contour_x
= x_mouse_x
;
3718 x_contour_y
= x_mouse_y
;
3720 else /* mouse above or same line as point */
3722 if (x_mouse_y
>= point_y
) /* Flipped. */
3724 mouse_below_point
= 1;
3726 outline_region (f
, f
->display
.x
->reverse_gc
,
3727 x_contour_x
, x_contour_y
, point_x
, point_y
);
3728 outline_region (f
, f
->display
.x
->cursor_gc
, point_x
, point_y
,
3729 x_mouse_x
, x_mouse_y
);
3731 else if (x_mouse_y
> x_contour_y
) /* Top clipped. */
3733 clip_contour_top (x_mouse_y
);
3735 else if (x_mouse_y
< x_contour_y
) /* Top extended. */
3737 extend_contour_top (x_mouse_y
);
3742 unread_command_event
= obj
;
3743 if (mouse_below_point
)
3745 contour_begin_x
= point_x
;
3746 contour_begin_y
= point_y
;
3747 contour_end_x
= x_contour_x
;
3748 contour_end_y
= x_contour_y
;
3752 contour_begin_x
= x_contour_x
;
3753 contour_begin_y
= x_contour_y
;
3754 contour_end_x
= point_x
;
3755 contour_end_y
= point_y
;
3760 DEFUN ("x-horizontal-line", Fx_horizontal_line
, Sx_horizontal_line
, 1, 1, "e",
3765 register Lisp_Object obj
;
3766 struct frame
*f
= selected_frame
;
3767 register struct window
*w
= XWINDOW (selected_window
);
3768 register GC line_gc
= f
->display
.x
->cursor_gc
;
3769 register GC erase_gc
= f
->display
.x
->reverse_gc
;
3771 char dash_list
[] = {6, 4, 6, 4};
3773 XGCValues gc_values
;
3775 register int previous_y
;
3776 register int line
= (x_mouse_y
+ 1) * f
->display
.x
->line_height
3777 + f
->display
.x
->internal_border_width
;
3778 register int left
= f
->display
.x
->internal_border_width
3780 * FONT_WIDTH (f
->display
.x
->font
));
3781 register int right
= left
+ (w
->width
3782 * FONT_WIDTH (f
->display
.x
->font
))
3783 - f
->display
.x
->internal_border_width
;
3787 gc_values
.foreground
= f
->display
.x
->cursor_pixel
;
3788 gc_values
.background
= f
->display
.x
->background_pixel
;
3789 gc_values
.line_width
= 1;
3790 gc_values
.line_style
= LineOnOffDash
;
3791 gc_values
.cap_style
= CapRound
;
3792 gc_values
.join_style
= JoinRound
;
3794 line_gc
= XCreateGC (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3795 GCLineStyle
| GCJoinStyle
| GCCapStyle
3796 | GCLineWidth
| GCForeground
| GCBackground
,
3798 XSetDashes (FRAME_X_DISPLAY (f
), line_gc
, 0, dash_list
, dashes
);
3799 gc_values
.foreground
= f
->display
.x
->background_pixel
;
3800 gc_values
.background
= f
->display
.x
->foreground_pixel
;
3801 erase_gc
= XCreateGC (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3802 GCLineStyle
| GCJoinStyle
| GCCapStyle
3803 | GCLineWidth
| GCForeground
| GCBackground
,
3805 XSetDashes (FRAME_X_DISPLAY (f
), erase_gc
, 0, dash_list
, dashes
);
3811 if (x_mouse_y
>= XINT (w
->top
)
3812 && x_mouse_y
< XINT (w
->top
) + XINT (w
->height
) - 1)
3814 previous_y
= x_mouse_y
;
3815 line
= (x_mouse_y
+ 1) * f
->display
.x
->line_height
3816 + f
->display
.x
->internal_border_width
;
3817 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3818 line_gc
, left
, line
, right
, line
);
3820 XFlush (FRAME_X_DISPLAY (f
));
3825 obj
= read_char (-1, 0, 0, Qnil
, 0);
3827 || (! EQ (Fcar (Fcdr (Fcdr (obj
))),
3828 Qvertical_scroll_bar
))
3832 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3833 erase_gc
, left
, line
, right
, line
);
3835 unread_command_event
= obj
;
3837 XFreeGC (FRAME_X_DISPLAY (f
), line_gc
);
3838 XFreeGC (FRAME_X_DISPLAY (f
), erase_gc
);
3843 while (x_mouse_y
== previous_y
);
3846 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3847 erase_gc
, left
, line
, right
, line
);
3854 /* These keep track of the rectangle following the pointer. */
3855 int mouse_track_top
, mouse_track_left
, mouse_track_width
;
3857 /* Offset in buffer of character under the pointer, or 0. */
3858 int mouse_buffer_offset
;
3860 DEFUN ("x-track-pointer", Fx_track_pointer
, Sx_track_pointer
, 0, 0, 0,
3861 "Track the pointer.")
3864 static Cursor current_pointer_shape
;
3865 FRAME_PTR f
= x_mouse_frame
;
3868 if (EQ (Vmouse_frame_part
, Qtext_part
)
3869 && (current_pointer_shape
!= f
->display
.x
->nontext_cursor
))
3874 current_pointer_shape
= f
->display
.x
->nontext_cursor
;
3875 XDefineCursor (FRAME_X_DISPLAY (f
),
3877 current_pointer_shape
);
3879 buf
= XBUFFER (XWINDOW (Vmouse_window
)->buffer
);
3880 c
= *(BUF_CHAR_ADDRESS (buf
, mouse_buffer_offset
));
3882 else if (EQ (Vmouse_frame_part
, Qmodeline_part
)
3883 && (current_pointer_shape
!= f
->display
.x
->modeline_cursor
))
3885 current_pointer_shape
= f
->display
.x
->modeline_cursor
;
3886 XDefineCursor (FRAME_X_DISPLAY (f
),
3888 current_pointer_shape
);
3891 XFlush (FRAME_X_DISPLAY (f
));
3897 DEFUN ("x-track-pointer", Fx_track_pointer
, Sx_track_pointer
, 1, 1, "e",
3898 "Draw rectangle around character under mouse pointer, if there is one.")
3902 struct window
*w
= XWINDOW (Vmouse_window
);
3903 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
3904 struct buffer
*b
= XBUFFER (w
->buffer
);
3907 if (! EQ (Vmouse_window
, selected_window
))
3910 if (EQ (event
, Qnil
))
3914 x_read_mouse_position (selected_frame
, &x
, &y
);
3918 mouse_track_width
= 0;
3919 mouse_track_left
= mouse_track_top
= -1;
3923 if ((x_mouse_x
!= mouse_track_left
3924 && (x_mouse_x
< mouse_track_left
3925 || x_mouse_x
> (mouse_track_left
+ mouse_track_width
)))
3926 || x_mouse_y
!= mouse_track_top
)
3928 int hp
= 0; /* Horizontal position */
3929 int len
= FRAME_CURRENT_GLYPHS (f
)->used
[x_mouse_y
];
3930 int p
= FRAME_CURRENT_GLYPHS (f
)->bufp
[x_mouse_y
];
3931 int tab_width
= XINT (b
->tab_width
);
3932 int ctl_arrow_p
= !NILP (b
->ctl_arrow
);
3934 int mode_line_vpos
= XFASTINT (w
->height
) + XFASTINT (w
->top
) - 1;
3935 int in_mode_line
= 0;
3937 if (! FRAME_CURRENT_GLYPHS (f
)->enable
[x_mouse_y
])
3940 /* Erase previous rectangle. */
3941 if (mouse_track_width
)
3943 x_rectangle (f
, f
->display
.x
->reverse_gc
,
3944 mouse_track_left
, mouse_track_top
,
3945 mouse_track_width
, 1);
3947 if ((mouse_track_left
== f
->phys_cursor_x
3948 || mouse_track_left
== f
->phys_cursor_x
- 1)
3949 && mouse_track_top
== f
->phys_cursor_y
)
3951 x_display_cursor (f
, 1);
3955 mouse_track_left
= x_mouse_x
;
3956 mouse_track_top
= x_mouse_y
;
3957 mouse_track_width
= 0;
3959 if (mouse_track_left
> len
) /* Past the end of line. */
3962 if (mouse_track_top
== mode_line_vpos
)
3968 if (tab_width
<= 0 || tab_width
> 20) tab_width
= 8;
3972 if (len
== f
->width
&& hp
== len
- 1 && c
!= '\n')
3978 mouse_track_width
= tab_width
- (hp
% tab_width
);
3980 hp
+= mouse_track_width
;
3983 mouse_track_left
= hp
- mouse_track_width
;
3989 mouse_track_width
= -1;
3993 if (ctl_arrow_p
&& (c
< 040 || c
== 0177))
3998 mouse_track_width
= 2;
4003 mouse_track_left
= hp
- mouse_track_width
;
4009 mouse_track_width
= 1;
4016 while (hp
<= x_mouse_x
);
4019 if (mouse_track_width
) /* Over text; use text pointer shape. */
4021 XDefineCursor (FRAME_X_DISPLAY (f
),
4023 f
->display
.x
->text_cursor
);
4024 x_rectangle (f
, f
->display
.x
->cursor_gc
,
4025 mouse_track_left
, mouse_track_top
,
4026 mouse_track_width
, 1);
4028 else if (in_mode_line
)
4029 XDefineCursor (FRAME_X_DISPLAY (f
),
4031 f
->display
.x
->modeline_cursor
);
4033 XDefineCursor (FRAME_X_DISPLAY (f
),
4035 f
->display
.x
->nontext_cursor
);
4038 XFlush (FRAME_X_DISPLAY (f
));
4041 obj
= read_char (-1, 0, 0, Qnil
, 0);
4044 while (CONSP (obj
) /* Mouse event */
4045 && EQ (Fcar (Fcdr (Fcdr (obj
))), Qnil
) /* Not scroll bar */
4046 && EQ (Vmouse_depressed
, Qnil
) /* Only motion events */
4047 && EQ (Vmouse_window
, selected_window
) /* In this window */
4050 unread_command_event
= obj
;
4052 if (mouse_track_width
)
4054 x_rectangle (f
, f
->display
.x
->reverse_gc
,
4055 mouse_track_left
, mouse_track_top
,
4056 mouse_track_width
, 1);
4057 mouse_track_width
= 0;
4058 if ((mouse_track_left
== f
->phys_cursor_x
4059 || mouse_track_left
- 1 == f
->phys_cursor_x
)
4060 && mouse_track_top
== f
->phys_cursor_y
)
4062 x_display_cursor (f
, 1);
4065 XDefineCursor (FRAME_X_DISPLAY (f
),
4067 f
->display
.x
->nontext_cursor
);
4068 XFlush (FRAME_X_DISPLAY (f
));
4078 /* Draw a pixmap specified by IMAGE_DATA of dimensions WIDTH and HEIGHT
4079 on the frame F at position X, Y. */
4081 x_draw_pixmap (f
, x
, y
, image_data
, width
, height
)
4083 int x
, y
, width
, height
;
4088 image
= XCreateBitmapFromData (FRAME_X_DISPLAY (f
),
4089 FRAME_X_WINDOW (f
), image_data
,
4091 XCopyPlane (FRAME_X_DISPLAY (f
), image
, FRAME_X_WINDOW (f
),
4092 f
->display
.x
->normal_gc
, 0, 0, width
, height
, x
, y
);
4096 #if 0 /* I'm told these functions are superfluous
4097 given the ability to bind function keys. */
4100 DEFUN ("x-rebind-key", Fx_rebind_key
, Sx_rebind_key
, 3, 3, 0,
4101 "Rebind X keysym KEYSYM, with MODIFIERS, to generate NEWSTRING.\n\
4102 KEYSYM is a string which conforms to the X keysym definitions found\n\
4103 in X11/keysymdef.h, sans the initial XK_. MODIFIERS is nil or a\n\
4104 list of strings specifying modifier keys such as Control_L, which must\n\
4105 also be depressed for NEWSTRING to appear.")
4106 (x_keysym
, modifiers
, newstring
)
4107 register Lisp_Object x_keysym
;
4108 register Lisp_Object modifiers
;
4109 register Lisp_Object newstring
;
4112 register KeySym keysym
;
4113 KeySym modifier_list
[16];
4116 CHECK_STRING (x_keysym
, 1);
4117 CHECK_STRING (newstring
, 3);
4119 keysym
= XStringToKeysym ((char *) XSTRING (x_keysym
)->data
);
4120 if (keysym
== NoSymbol
)
4121 error ("Keysym does not exist");
4123 if (NILP (modifiers
))
4124 XRebindKeysym (x_current_display
, keysym
, modifier_list
, 0,
4125 XSTRING (newstring
)->data
, XSTRING (newstring
)->size
);
4128 register Lisp_Object rest
, mod
;
4131 for (rest
= modifiers
; !NILP (rest
); rest
= Fcdr (rest
))
4134 error ("Can't have more than 16 modifiers");
4137 CHECK_STRING (mod
, 3);
4138 modifier_list
[i
] = XStringToKeysym ((char *) XSTRING (mod
)->data
);
4140 if (modifier_list
[i
] == NoSymbol
4141 || !(IsModifierKey (modifier_list
[i
])
4142 || ((unsigned)(modifier_list
[i
]) == XK_Mode_switch
)
4143 || ((unsigned)(modifier_list
[i
]) == XK_Num_Lock
)))
4145 if (modifier_list
[i
] == NoSymbol
4146 || !IsModifierKey (modifier_list
[i
]))
4148 error ("Element is not a modifier keysym");
4152 XRebindKeysym (x_current_display
, keysym
, modifier_list
, i
,
4153 XSTRING (newstring
)->data
, XSTRING (newstring
)->size
);
4159 DEFUN ("x-rebind-keys", Fx_rebind_keys
, Sx_rebind_keys
, 2, 2, 0,
4160 "Rebind KEYCODE to list of strings STRINGS.\n\
4161 STRINGS should be a list of 16 elements, one for each shift combination.\n\
4162 nil as element means don't change.\n\
4163 See the documentation of `x-rebind-key' for more information.")
4165 register Lisp_Object keycode
;
4166 register Lisp_Object strings
;
4168 register Lisp_Object item
;
4169 register unsigned char *rawstring
;
4170 KeySym rawkey
, modifier
[1];
4172 register unsigned i
;
4175 CHECK_NUMBER (keycode
, 1);
4176 CHECK_CONS (strings
, 2);
4177 rawkey
= (KeySym
) ((unsigned) (XINT (keycode
))) & 255;
4178 for (i
= 0; i
<= 15; strings
= Fcdr (strings
), i
++)
4180 item
= Fcar (strings
);
4183 CHECK_STRING (item
, 2);
4184 strsize
= XSTRING (item
)->size
;
4185 rawstring
= (unsigned char *) xmalloc (strsize
);
4186 bcopy (XSTRING (item
)->data
, rawstring
, strsize
);
4187 modifier
[1] = 1 << i
;
4188 XRebindKeysym (x_current_display
, rawkey
, modifier
, 1,
4189 rawstring
, strsize
);
4194 #endif /* HAVE_X11 */
4197 #ifndef HAVE_XSCREENNUMBEROFSCREEN
4199 XScreenNumberOfScreen (scr
)
4200 register Screen
*scr
;
4202 register Display
*dpy
;
4203 register Screen
*dpyscr
;
4207 dpyscr
= dpy
->screens
;
4209 for (i
= 0; i
< dpy
->nscreens
; i
++, dpyscr
++)
4215 #endif /* not HAVE_XSCREENNUMBEROFSCREEN */
4218 select_visual (dpy
, screen
, depth
)
4221 unsigned int *depth
;
4224 XVisualInfo
*vinfo
, vinfo_template
;
4227 v
= DefaultVisualOfScreen (screen
);
4230 vinfo_template
.visualid
= XVisualIDFromVisual (v
);
4232 vinfo_template
.visualid
= v
->visualid
;
4235 vinfo_template
.screen
= XScreenNumberOfScreen (screen
);
4237 vinfo
= XGetVisualInfo (dpy
,
4238 VisualIDMask
| VisualScreenMask
, &vinfo_template
,
4241 fatal ("Can't get proper X visual info");
4243 if ((1 << vinfo
->depth
) == vinfo
->colormap_size
)
4244 *depth
= vinfo
->depth
;
4248 int n
= vinfo
->colormap_size
- 1;
4257 XFree ((char *) vinfo
);
4261 /* Return the X display structure for the display named NAME.
4262 Open a new connection if necessary. */
4264 struct x_display_info
*
4265 x_display_info_for_name (name
)
4268 struct x_display_info
*dpyinfo
;
4270 CHECK_STRING (name
, 0);
4272 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
4275 tem
= Fstring_equal (dpyinfo
->name
, name
);
4280 validate_x_resource_name ();
4282 dpyinfo
= x_term_init (name
, (unsigned char *)0,
4283 XSTRING (Vx_resource_name
)->data
);
4286 XSETFASTINT (Vwindow_system_version
, 11);
4291 DEFUN ("x-open-connection", Fx_open_connection
, Sx_open_connection
,
4292 1, 2, 0, "Open a connection to an X server.\n\
4293 DISPLAY is the name of the display to connect to.\n\
4294 Optional second arg XRM_STRING is a string of resources in xrdb format.")
4295 (display
, xrm_string
)
4296 Lisp_Object display
, xrm_string
;
4298 unsigned int n_planes
;
4299 unsigned char *xrm_option
;
4300 struct x_display_info
*dpyinfo
;
4302 CHECK_STRING (display
, 0);
4303 if (! NILP (xrm_string
))
4304 CHECK_STRING (xrm_string
, 1);
4306 if (! NILP (xrm_string
))
4307 xrm_option
= (unsigned char *) XSTRING (xrm_string
)->data
;
4309 xrm_option
= (unsigned char *) 0;
4311 validate_x_resource_name ();
4313 /* This is what opens the connection and sets x_current_display.
4314 This also initializes many symbols, such as those used for input. */
4315 dpyinfo
= x_term_init (display
, xrm_option
,
4316 XSTRING (Vx_resource_name
)->data
);
4320 XSETFASTINT (Vwindow_system_version
, 11);
4324 DEFUN ("x-close-current-connection", Fx_close_current_connection
,
4325 Sx_close_current_connection
,
4326 1, 1, 0, "Close the connection to frame FRAME's X server.")
4331 /* Note: If we're going to call check_x here, then the fatal error
4332 can't happen. For the moment, this check is just for safety,
4333 so a user won't try out the function and get a crash. If it's
4334 really intended only to be called when killing emacs, then there's
4335 no reason for it to have a lisp interface at all. */
4337 CHECK_LIVE_FRAME (frame
, 0);
4338 dpy
= FRAME_X_DISPLAY (XFRAME (frame
));
4340 /* This is ONLY used when killing emacs; For switching displays
4341 we'll have to take care of setting CloseDownMode elsewhere. */
4346 XSetCloseDownMode (dpy
, DestroyAll
);
4347 XCloseDisplay (dpy
);
4351 error ("No current X display connection to close");
4356 DEFUN ("x-synchronize", Fx_synchronize
, Sx_synchronize
,
4357 1, 2, 0, "If ON is non-nil, report X errors as soon as the erring request is made.\n\
4358 If ON is nil, allow buffering of requests.\n\
4359 Turning on synchronization prohibits the Xlib routines from buffering\n\
4360 requests and seriously degrades performance, but makes debugging much\n\
4363 Lisp_Object frame
, on
;
4365 struct x_display_info
*dpyinfo
= check_x_display_info (frame
);
4367 XSynchronize (dpyinfo
->display
, !EQ (on
, Qnil
));
4372 /* Wait for responses to all X commands issued so far for frame F. */
4379 XSync (FRAME_X_DISPLAY (f
), False
);
4385 /* This is zero if not using X windows. */
4388 /* The section below is built by the lisp expression at the top of the file,
4389 just above where these variables are declared. */
4390 /*&&& init symbols here &&&*/
4391 Qauto_raise
= intern ("auto-raise");
4392 staticpro (&Qauto_raise
);
4393 Qauto_lower
= intern ("auto-lower");
4394 staticpro (&Qauto_lower
);
4395 Qbackground_color
= intern ("background-color");
4396 staticpro (&Qbackground_color
);
4397 Qbar
= intern ("bar");
4399 Qborder_color
= intern ("border-color");
4400 staticpro (&Qborder_color
);
4401 Qborder_width
= intern ("border-width");
4402 staticpro (&Qborder_width
);
4403 Qbox
= intern ("box");
4405 Qcursor_color
= intern ("cursor-color");
4406 staticpro (&Qcursor_color
);
4407 Qcursor_type
= intern ("cursor-type");
4408 staticpro (&Qcursor_type
);
4409 Qfont
= intern ("font");
4411 Qforeground_color
= intern ("foreground-color");
4412 staticpro (&Qforeground_color
);
4413 Qgeometry
= intern ("geometry");
4414 staticpro (&Qgeometry
);
4415 Qicon_left
= intern ("icon-left");
4416 staticpro (&Qicon_left
);
4417 Qicon_top
= intern ("icon-top");
4418 staticpro (&Qicon_top
);
4419 Qicon_type
= intern ("icon-type");
4420 staticpro (&Qicon_type
);
4421 Qinternal_border_width
= intern ("internal-border-width");
4422 staticpro (&Qinternal_border_width
);
4423 Qleft
= intern ("left");
4425 Qmouse_color
= intern ("mouse-color");
4426 staticpro (&Qmouse_color
);
4427 Qnone
= intern ("none");
4429 Qparent_id
= intern ("parent-id");
4430 staticpro (&Qparent_id
);
4431 Qscroll_bar_width
= intern ("scroll-bar-width");
4432 staticpro (&Qscroll_bar_width
);
4433 Qsuppress_icon
= intern ("suppress-icon");
4434 staticpro (&Qsuppress_icon
);
4435 Qtop
= intern ("top");
4437 Qundefined_color
= intern ("undefined-color");
4438 staticpro (&Qundefined_color
);
4439 Qvertical_scroll_bars
= intern ("vertical-scroll-bars");
4440 staticpro (&Qvertical_scroll_bars
);
4441 Qvisibility
= intern ("visibility");
4442 staticpro (&Qvisibility
);
4443 Qwindow_id
= intern ("window-id");
4444 staticpro (&Qwindow_id
);
4445 Qx_frame_parameter
= intern ("x-frame-parameter");
4446 staticpro (&Qx_frame_parameter
);
4447 Qx_resource_name
= intern ("x-resource-name");
4448 staticpro (&Qx_resource_name
);
4449 Quser_position
= intern ("user-position");
4450 staticpro (&Quser_position
);
4451 Quser_size
= intern ("user-size");
4452 staticpro (&Quser_size
);
4453 Qdisplay
= intern ("display");
4454 staticpro (&Qdisplay
);
4455 /* This is the end of symbol initialization. */
4457 Fput (Qundefined_color
, Qerror_conditions
,
4458 Fcons (Qundefined_color
, Fcons (Qerror
, Qnil
)));
4459 Fput (Qundefined_color
, Qerror_message
,
4460 build_string ("Undefined color"));
4462 init_x_parm_symbols ();
4464 DEFVAR_LISP ("x-bitmap-file-path", &Vx_bitmap_file_path
,
4465 "List of directories to search for bitmap files for X.");
4466 Vx_bitmap_file_path
= Fcons (build_string (PATH_BITMAPS
), Qnil
);
4468 DEFVAR_LISP ("x-pointer-shape", &Vx_pointer_shape
,
4469 "The shape of the pointer when over text.\n\
4470 Changing the value does not affect existing frames\n\
4471 unless you set the mouse color.");
4472 Vx_pointer_shape
= Qnil
;
4474 DEFVAR_LISP ("x-resource-name", &Vx_resource_name
,
4475 "The name Emacs uses to look up X resources; for internal use only.\n\
4476 `x-get-resource' uses this as the first component of the instance name\n\
4477 when requesting resource values.\n\
4478 Emacs initially sets `x-resource-name' to the name under which Emacs\n\
4479 was invoked, or to the value specified with the `-name' or `-rn'\n\
4480 switches, if present.");
4481 Vx_resource_name
= Qnil
;
4483 #if 0 /* This doesn't really do anything. */
4484 DEFVAR_INT ("x-nontext-pointer-shape", &Vx_nontext_pointer_shape
,
4485 "The shape of the pointer when not over text.\n\
4486 This variable takes effect when you create a new frame\n\
4487 or when you set the mouse color.");
4489 Vx_nontext_pointer_shape
= Qnil
;
4491 #if 0 /* This doesn't really do anything. */
4492 DEFVAR_INT ("x-mode-pointer-shape", &Vx_mode_pointer_shape
,
4493 "The shape of the pointer when over the mode line.\n\
4494 This variable takes effect when you create a new frame\n\
4495 or when you set the mouse color.");
4497 Vx_mode_pointer_shape
= Qnil
;
4499 DEFVAR_INT ("x-sensitive-text-pointer-shape",
4500 &Vx_sensitive_text_pointer_shape
,
4501 "The shape of the pointer when over mouse-sensitive text.\n\
4502 This variable takes effect when you create a new frame\n\
4503 or when you set the mouse color.");
4504 Vx_sensitive_text_pointer_shape
= Qnil
;
4506 DEFVAR_LISP ("x-cursor-fore-pixel", &Vx_cursor_fore_pixel
,
4507 "A string indicating the foreground color of the cursor box.");
4508 Vx_cursor_fore_pixel
= Qnil
;
4510 DEFVAR_LISP ("x-no-window-manager", &Vx_no_window_manager
,
4511 "Non-nil if no X window manager is in use.");
4513 #ifdef USE_X_TOOLKIT
4514 Fprovide (intern ("x-toolkit"));
4517 defsubr (&Sx_get_resource
);
4519 defsubr (&Sx_draw_rectangle
);
4520 defsubr (&Sx_erase_rectangle
);
4521 defsubr (&Sx_contour_region
);
4522 defsubr (&Sx_uncontour_region
);
4524 defsubr (&Sx_list_fonts
);
4525 defsubr (&Sx_display_color_p
);
4526 defsubr (&Sx_display_grayscale_p
);
4527 defsubr (&Sx_color_defined_p
);
4528 defsubr (&Sx_color_values
);
4529 defsubr (&Sx_server_max_request_size
);
4530 defsubr (&Sx_server_vendor
);
4531 defsubr (&Sx_server_version
);
4532 defsubr (&Sx_display_pixel_width
);
4533 defsubr (&Sx_display_pixel_height
);
4534 defsubr (&Sx_display_mm_width
);
4535 defsubr (&Sx_display_mm_height
);
4536 defsubr (&Sx_display_screens
);
4537 defsubr (&Sx_display_planes
);
4538 defsubr (&Sx_display_color_cells
);
4539 defsubr (&Sx_display_visual_class
);
4540 defsubr (&Sx_display_backing_store
);
4541 defsubr (&Sx_display_save_under
);
4543 defsubr (&Sx_rebind_key
);
4544 defsubr (&Sx_rebind_keys
);
4545 defsubr (&Sx_track_pointer
);
4546 defsubr (&Sx_grab_pointer
);
4547 defsubr (&Sx_ungrab_pointer
);
4549 defsubr (&Sx_parse_geometry
);
4550 defsubr (&Sx_create_frame
);
4551 defsubr (&Sfocus_frame
);
4552 defsubr (&Sunfocus_frame
);
4554 defsubr (&Sx_horizontal_line
);
4556 defsubr (&Sx_open_connection
);
4557 defsubr (&Sx_close_current_connection
);
4558 defsubr (&Sx_synchronize
);
4561 #endif /* HAVE_X_WINDOWS */