]> code.delx.au - gnu-emacs/blob - src/xfns.c
[USE_X_TOOLKIT] (x_window): Always pass position in geometry.
[gnu-emacs] / src / xfns.c
1 /* Functions for the X window system.
2 Copyright (C) 1989, 1992, 1993, 1994, 1995 Free Software Foundation.
3
4 This file is part of GNU Emacs.
5
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)
9 any later version.
10
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.
15
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. */
19
20 /* Completely rewritten by Richard Stallman. */
21
22 /* Rewritten for X11 by Joseph Arceneaux */
23
24 #include <signal.h>
25 #include <config.h>
26
27 /* This makes the fields of a Display accessible, in Xlib header files. */
28 #define XLIB_ILLEGAL_ACCESS
29
30 #include "lisp.h"
31 #include "xterm.h"
32 #include "frame.h"
33 #include "window.h"
34 #include "buffer.h"
35 #include "dispextern.h"
36 #include "keyboard.h"
37 #include "blockinput.h"
38 #include "paths.h"
39
40 #ifdef HAVE_X_WINDOWS
41 extern void abort ();
42
43 #ifndef VMS
44 #if 1 /* Used to be #ifdef EMACS_BITMAP_FILES, but this should always work. */
45 #include "bitmaps/gray.xbm"
46 #else
47 #include <X11/bitmaps/gray>
48 #endif
49 #else
50 #include "[.bitmaps]gray.xbm"
51 #endif
52
53 #ifdef USE_X_TOOLKIT
54 #include <X11/Shell.h>
55
56 #include <X11/Xaw/Paned.h>
57 #include <X11/Xaw/Label.h>
58
59 #ifdef USG
60 #undef USG /* ####KLUDGE for Solaris 2.2 and up */
61 #include <X11/Xos.h>
62 #define USG
63 #else
64 #include <X11/Xos.h>
65 #endif
66
67 #include "widget.h"
68
69 #include "../lwlib/lwlib.h"
70
71 /* Do the EDITRES protocol if running X11R5 */
72 #if (XtSpecificationRelease >= 5)
73 #define HACK_EDITRES
74 extern void _XEditResCheckMessages ();
75 #endif /* R5 + Athena */
76
77 /* Unique id counter for widgets created by the Lucid Widget
78 Library. */
79 extern LWLIB_ID widget_id_tick;
80
81 /* This is part of a kludge--see lwlib/xlwmenu.c. */
82 XFontStruct *xlwmenu_default_font;
83
84 extern void free_frame_menubar ();
85 #endif /* USE_X_TOOLKIT */
86
87 #define min(a,b) ((a) < (b) ? (a) : (b))
88 #define max(a,b) ((a) > (b) ? (a) : (b))
89
90 #ifdef HAVE_X11R4
91 #define MAXREQUEST(dpy) (XMaxRequestSize (dpy))
92 #else
93 #define MAXREQUEST(dpy) ((dpy)->max_request_size)
94 #endif
95
96 /* The name we're using in resource queries. */
97 Lisp_Object Vx_resource_name;
98
99 /* The background and shape of the mouse pointer, and shape when not
100 over text or in the modeline. */
101 Lisp_Object Vx_pointer_shape, Vx_nontext_pointer_shape, Vx_mode_pointer_shape;
102 /* The shape when over mouse-sensitive text. */
103 Lisp_Object Vx_sensitive_text_pointer_shape;
104
105 /* Color of chars displayed in cursor box. */
106 Lisp_Object Vx_cursor_fore_pixel;
107
108 /* Nonzero if using X. */
109 static int x_in_use;
110
111 /* Non nil if no window manager is in use. */
112 Lisp_Object Vx_no_window_manager;
113
114 /* Search path for bitmap files. */
115 Lisp_Object Vx_bitmap_file_path;
116
117 /* Evaluate this expression to rebuild the section of syms_of_xfns
118 that initializes and staticpros the symbols declared below. Note
119 that Emacs 18 has a bug that keeps C-x C-e from being able to
120 evaluate this expression.
121
122 (progn
123 ;; Accumulate a list of the symbols we want to initialize from the
124 ;; declarations at the top of the file.
125 (goto-char (point-min))
126 (search-forward "/\*&&& symbols declared here &&&*\/\n")
127 (let (symbol-list)
128 (while (looking-at "Lisp_Object \\(Q[a-z_]+\\)")
129 (setq symbol-list
130 (cons (buffer-substring (match-beginning 1) (match-end 1))
131 symbol-list))
132 (forward-line 1))
133 (setq symbol-list (nreverse symbol-list))
134 ;; Delete the section of syms_of_... where we initialize the symbols.
135 (search-forward "\n /\*&&& init symbols here &&&*\/\n")
136 (let ((start (point)))
137 (while (looking-at "^ Q")
138 (forward-line 2))
139 (kill-region start (point)))
140 ;; Write a new symbol initialization section.
141 (while symbol-list
142 (insert (format " %s = intern (\"" (car symbol-list)))
143 (let ((start (point)))
144 (insert (substring (car symbol-list) 1))
145 (subst-char-in-region start (point) ?_ ?-))
146 (insert (format "\");\n staticpro (&%s);\n" (car symbol-list)))
147 (setq symbol-list (cdr symbol-list)))))
148
149 */
150
151 /*&&& symbols declared here &&&*/
152 Lisp_Object Qauto_raise;
153 Lisp_Object Qauto_lower;
154 Lisp_Object Qbackground_color;
155 Lisp_Object Qbar;
156 Lisp_Object Qborder_color;
157 Lisp_Object Qborder_width;
158 Lisp_Object Qbox;
159 Lisp_Object Qcursor_color;
160 Lisp_Object Qcursor_type;
161 Lisp_Object Qfont;
162 Lisp_Object Qforeground_color;
163 Lisp_Object Qgeometry;
164 Lisp_Object Qicon_left;
165 Lisp_Object Qicon_top;
166 Lisp_Object Qicon_type;
167 Lisp_Object Qinternal_border_width;
168 Lisp_Object Qleft;
169 Lisp_Object Qmouse_color;
170 Lisp_Object Qnone;
171 Lisp_Object Qparent_id;
172 Lisp_Object Qscroll_bar_width;
173 Lisp_Object Qsuppress_icon;
174 Lisp_Object Qtop;
175 Lisp_Object Qundefined_color;
176 Lisp_Object Qvertical_scroll_bars;
177 Lisp_Object Qvisibility;
178 Lisp_Object Qwindow_id;
179 Lisp_Object Qx_frame_parameter;
180 Lisp_Object Qx_resource_name;
181 Lisp_Object Quser_position;
182 Lisp_Object Quser_size;
183 Lisp_Object Qdisplay;
184
185 /* The below are defined in frame.c. */
186 extern Lisp_Object Qheight, Qminibuffer, Qname, Qonly, Qwidth;
187 extern Lisp_Object Qunsplittable, Qmenu_bar_lines;
188
189 extern Lisp_Object Vwindow_system_version;
190
191 \f
192 /* Error if we are not connected to X. */
193 void
194 check_x ()
195 {
196 if (! x_in_use)
197 error ("X windows are not in use or not initialized");
198 }
199
200 /* Nonzero if using X for display. */
201
202 int
203 using_x_p ()
204 {
205 return x_in_use;
206 }
207
208 /* Extract a frame as a FRAME_PTR, defaulting to the selected frame
209 and checking validity for X. */
210
211 FRAME_PTR
212 check_x_frame (frame)
213 Lisp_Object frame;
214 {
215 FRAME_PTR f;
216
217 if (NILP (frame))
218 f = selected_frame;
219 else
220 {
221 CHECK_LIVE_FRAME (frame, 0);
222 f = XFRAME (frame);
223 }
224 if (! FRAME_X_P (f))
225 error ("non-X frame used");
226 return f;
227 }
228
229 /* Let the user specify an X display with a frame.
230 nil stands for the selected frame--or, if that is not an X frame,
231 the first X display on the list. */
232
233 static struct x_display_info *
234 check_x_display_info (frame)
235 Lisp_Object frame;
236 {
237 if (NILP (frame))
238 {
239 if (FRAME_X_P (selected_frame))
240 return FRAME_X_DISPLAY_INFO (selected_frame);
241 else if (x_display_list != 0)
242 return x_display_list;
243 else
244 error ("X windows are not in use or not initialized");
245 }
246 else if (STRINGP (frame))
247 return x_display_info_for_name (frame);
248 else
249 {
250 FRAME_PTR f;
251
252 CHECK_LIVE_FRAME (frame, 0);
253 f = XFRAME (frame);
254 if (! FRAME_X_P (f))
255 error ("non-X frame used");
256 return FRAME_X_DISPLAY_INFO (f);
257 }
258 }
259 \f
260 /* Return the Emacs frame-object corresponding to an X window.
261 It could be the frame's main window or an icon window. */
262
263 /* This function can be called during GC, so use GC_xxx type test macros. */
264
265 struct frame *
266 x_window_to_frame (dpyinfo, wdesc)
267 struct x_display_info *dpyinfo;
268 int wdesc;
269 {
270 Lisp_Object tail, frame;
271 struct frame *f;
272
273 for (tail = Vframe_list; GC_CONSP (tail); tail = XCONS (tail)->cdr)
274 {
275 frame = XCONS (tail)->car;
276 if (!GC_FRAMEP (frame))
277 continue;
278 f = XFRAME (frame);
279 if (f->display.nothing == 1 || FRAME_X_DISPLAY_INFO (f) != dpyinfo)
280 continue;
281 #ifdef USE_X_TOOLKIT
282 if ((f->display.x->edit_widget
283 && XtWindow (f->display.x->edit_widget) == wdesc)
284 || f->display.x->icon_desc == wdesc)
285 return f;
286 #else /* not USE_X_TOOLKIT */
287 if (FRAME_X_WINDOW (f) == wdesc
288 || f->display.x->icon_desc == wdesc)
289 return f;
290 #endif /* not USE_X_TOOLKIT */
291 }
292 return 0;
293 }
294
295 #ifdef USE_X_TOOLKIT
296 /* Like x_window_to_frame but also compares the window with the widget's
297 windows. */
298
299 struct frame *
300 x_any_window_to_frame (dpyinfo, wdesc)
301 struct x_display_info *dpyinfo;
302 int wdesc;
303 {
304 Lisp_Object tail, frame;
305 struct frame *f;
306 struct x_display *x;
307
308 for (tail = Vframe_list; GC_CONSP (tail); tail = XCONS (tail)->cdr)
309 {
310 frame = XCONS (tail)->car;
311 if (!GC_FRAMEP (frame))
312 continue;
313 f = XFRAME (frame);
314 if (f->display.nothing == 1 || FRAME_X_DISPLAY_INFO (f) != dpyinfo)
315 continue;
316 x = f->display.x;
317 /* This frame matches if the window is any of its widgets. */
318 if (wdesc == XtWindow (x->widget)
319 || wdesc == XtWindow (x->column_widget)
320 || wdesc == XtWindow (x->edit_widget))
321 return f;
322 /* Match if the window is this frame's menubar. */
323 if (lw_window_is_in_menubar (wdesc, x->menubar_widget))
324 return f;
325 }
326 return 0;
327 }
328
329 /* Likewise, but exclude the menu bar widget. */
330
331 struct frame *
332 x_non_menubar_window_to_frame (dpyinfo, wdesc)
333 struct x_display_info *dpyinfo;
334 int wdesc;
335 {
336 Lisp_Object tail, frame;
337 struct frame *f;
338 struct x_display *x;
339
340 for (tail = Vframe_list; GC_CONSP (tail); tail = XCONS (tail)->cdr)
341 {
342 frame = XCONS (tail)->car;
343 if (!GC_FRAMEP (frame))
344 continue;
345 f = XFRAME (frame);
346 if (f->display.nothing == 1 || FRAME_X_DISPLAY_INFO (f) != dpyinfo)
347 continue;
348 x = f->display.x;
349 /* This frame matches if the window is any of its widgets. */
350 if (wdesc == XtWindow (x->widget)
351 || wdesc == XtWindow (x->column_widget)
352 || wdesc == XtWindow (x->edit_widget))
353 return f;
354 }
355 return 0;
356 }
357
358 /* Return the frame whose principal (outermost) window is WDESC.
359 If WDESC is some other (smaller) window, we return 0. */
360
361 struct frame *
362 x_top_window_to_frame (dpyinfo, wdesc)
363 struct x_display_info *dpyinfo;
364 int wdesc;
365 {
366 Lisp_Object tail, frame;
367 struct frame *f;
368 struct x_display *x;
369
370 for (tail = Vframe_list; GC_CONSP (tail); tail = XCONS (tail)->cdr)
371 {
372 frame = XCONS (tail)->car;
373 if (!GC_FRAMEP (frame))
374 continue;
375 f = XFRAME (frame);
376 if (f->display.nothing == 1 || FRAME_X_DISPLAY_INFO (f) != dpyinfo)
377 continue;
378 x = f->display.x;
379 /* This frame matches if the window is its topmost widget. */
380 if (wdesc == XtWindow (x->widget))
381 return f;
382 /* Match if the window is this frame's menubar. */
383 if (x->menubar_widget
384 && wdesc == XtWindow (x->menubar_widget))
385 return f;
386 }
387 return 0;
388 }
389 #endif /* USE_X_TOOLKIT */
390
391 \f
392
393 /* Code to deal with bitmaps. Bitmaps are referenced by their bitmap
394 id, which is just an int that this section returns. Bitmaps are
395 reference counted so they can be shared among frames.
396
397 Bitmap indices are guaranteed to be > 0, so a negative number can
398 be used to indicate no bitmap.
399
400 If you use x_create_bitmap_from_data, then you must keep track of
401 the bitmaps yourself. That is, creating a bitmap from the same
402 data more than once will not be caught. */
403
404
405 /* Functions to access the contents of a bitmap, given an id. */
406
407 int
408 x_bitmap_height (f, id)
409 FRAME_PTR f;
410 int id;
411 {
412 return FRAME_X_DISPLAY_INFO (f)->bitmaps[id - 1].height;
413 }
414
415 int
416 x_bitmap_width (f, id)
417 FRAME_PTR f;
418 int id;
419 {
420 return FRAME_X_DISPLAY_INFO (f)->bitmaps[id - 1].width;
421 }
422
423 int
424 x_bitmap_pixmap (f, id)
425 FRAME_PTR f;
426 int id;
427 {
428 return FRAME_X_DISPLAY_INFO (f)->bitmaps[id - 1].pixmap;
429 }
430
431
432 /* Allocate a new bitmap record. Returns index of new record. */
433
434 static int
435 x_allocate_bitmap_record (f)
436 FRAME_PTR f;
437 {
438 struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
439 int i;
440
441 if (dpyinfo->bitmaps == NULL)
442 {
443 dpyinfo->bitmaps_size = 10;
444 dpyinfo->bitmaps
445 = (struct x_bitmap_record *) xmalloc (dpyinfo->bitmaps_size * sizeof (struct x_bitmap_record));
446 dpyinfo->bitmaps_last = 1;
447 return 1;
448 }
449
450 if (dpyinfo->bitmaps_last < dpyinfo->bitmaps_size)
451 return ++dpyinfo->bitmaps_last;
452
453 for (i = 0; i < dpyinfo->bitmaps_size; ++i)
454 if (dpyinfo->bitmaps[i].refcount == 0)
455 return i + 1;
456
457 dpyinfo->bitmaps_size *= 2;
458 dpyinfo->bitmaps
459 = (struct x_bitmap_record *) xrealloc (dpyinfo->bitmaps,
460 dpyinfo->bitmaps_size * sizeof (struct x_bitmap_record));
461 return ++dpyinfo->bitmaps_last;
462 }
463
464 /* Add one reference to the reference count of the bitmap with id ID. */
465
466 void
467 x_reference_bitmap (f, id)
468 FRAME_PTR f;
469 int id;
470 {
471 ++FRAME_X_DISPLAY_INFO (f)->bitmaps[id - 1].refcount;
472 }
473
474 /* Create a bitmap for frame F from a HEIGHT x WIDTH array of bits at BITS. */
475
476 int
477 x_create_bitmap_from_data (f, bits, width, height)
478 struct frame *f;
479 char *bits;
480 unsigned int width, height;
481 {
482 struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
483 Pixmap bitmap;
484 int id;
485
486 bitmap = XCreateBitmapFromData (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
487 bits, width, height);
488
489 if (! bitmap)
490 return -1;
491
492 id = x_allocate_bitmap_record (f);
493 dpyinfo->bitmaps[id - 1].pixmap = bitmap;
494 dpyinfo->bitmaps[id - 1].file = NULL;
495 dpyinfo->bitmaps[id - 1].refcount = 1;
496 dpyinfo->bitmaps[id - 1].depth = 1;
497 dpyinfo->bitmaps[id - 1].height = height;
498 dpyinfo->bitmaps[id - 1].width = width;
499
500 return id;
501 }
502
503 /* Create bitmap from file FILE for frame F. */
504
505 int
506 x_create_bitmap_from_file (f, file)
507 struct frame *f;
508 Lisp_Object file;
509 {
510 struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
511 unsigned int width, height;
512 Pixmap bitmap;
513 int xhot, yhot, result, id;
514 Lisp_Object found;
515 int fd;
516 char *filename;
517
518 /* Look for an existing bitmap with the same name. */
519 for (id = 0; id < dpyinfo->bitmaps_last; ++id)
520 {
521 if (dpyinfo->bitmaps[id].refcount
522 && dpyinfo->bitmaps[id].file
523 && !strcmp (dpyinfo->bitmaps[id].file, (char *) XSTRING (file)->data))
524 {
525 ++dpyinfo->bitmaps[id].refcount;
526 return id + 1;
527 }
528 }
529
530 /* Search bitmap-file-path for the file, if appropriate. */
531 fd = openp (Vx_bitmap_file_path, file, "", &found, 0);
532 if (fd < 0)
533 return -1;
534 close (fd);
535
536 filename = (char *) XSTRING (found)->data;
537
538 result = XReadBitmapFile (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
539 filename, &width, &height, &bitmap, &xhot, &yhot);
540 if (result != BitmapSuccess)
541 return -1;
542
543 id = x_allocate_bitmap_record (f);
544 dpyinfo->bitmaps[id - 1].pixmap = bitmap;
545 dpyinfo->bitmaps[id - 1].refcount = 1;
546 dpyinfo->bitmaps[id - 1].file = (char *) xmalloc (XSTRING (file)->size + 1);
547 dpyinfo->bitmaps[id - 1].depth = 1;
548 dpyinfo->bitmaps[id - 1].height = height;
549 dpyinfo->bitmaps[id - 1].width = width;
550 strcpy (dpyinfo->bitmaps[id - 1].file, XSTRING (file)->data);
551
552 return id;
553 }
554
555 /* Remove reference to bitmap with id number ID. */
556
557 int
558 x_destroy_bitmap (f, id)
559 FRAME_PTR f;
560 int id;
561 {
562 struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
563
564 if (id > 0)
565 {
566 --dpyinfo->bitmaps[id - 1].refcount;
567 if (dpyinfo->bitmaps[id - 1].refcount == 0)
568 {
569 XFreePixmap (FRAME_X_DISPLAY (f), dpyinfo->bitmaps[id - 1].pixmap);
570 if (dpyinfo->bitmaps[id - 1].file)
571 {
572 free (dpyinfo->bitmaps[id - 1].file);
573 dpyinfo->bitmaps[id - 1].file = NULL;
574 }
575 }
576 }
577 }
578
579 /* Free all the bitmaps for the display specified by DPYINFO. */
580
581 static void
582 x_destroy_all_bitmaps (dpyinfo)
583 struct x_display_info *dpyinfo;
584 {
585 int i;
586 for (i = 0; i < dpyinfo->bitmaps_last; i++)
587 if (dpyinfo->bitmaps[i].refcount > 0)
588 {
589 XFreePixmap (dpyinfo->display, dpyinfo->bitmaps[i].pixmap);
590 if (dpyinfo->bitmaps[i].file)
591 free (dpyinfo->bitmaps[i].file);
592 }
593 dpyinfo->bitmaps_last = 0;
594 }
595 \f
596 /* Connect the frame-parameter names for X frames
597 to the ways of passing the parameter values to the window system.
598
599 The name of a parameter, as a Lisp symbol,
600 has an `x-frame-parameter' property which is an integer in Lisp
601 but can be interpreted as an `enum x_frame_parm' in C. */
602
603 enum x_frame_parm
604 {
605 X_PARM_FOREGROUND_COLOR,
606 X_PARM_BACKGROUND_COLOR,
607 X_PARM_MOUSE_COLOR,
608 X_PARM_CURSOR_COLOR,
609 X_PARM_BORDER_COLOR,
610 X_PARM_ICON_TYPE,
611 X_PARM_FONT,
612 X_PARM_BORDER_WIDTH,
613 X_PARM_INTERNAL_BORDER_WIDTH,
614 X_PARM_NAME,
615 X_PARM_AUTORAISE,
616 X_PARM_AUTOLOWER,
617 X_PARM_VERT_SCROLL_BAR,
618 X_PARM_VISIBILITY,
619 X_PARM_MENU_BAR_LINES
620 };
621
622
623 struct x_frame_parm_table
624 {
625 char *name;
626 void (*setter)( /* struct frame *frame, Lisp_Object val, oldval */ );
627 };
628
629 void x_set_foreground_color ();
630 void x_set_background_color ();
631 void x_set_mouse_color ();
632 void x_set_cursor_color ();
633 void x_set_border_color ();
634 void x_set_cursor_type ();
635 void x_set_icon_type ();
636 void x_set_font ();
637 void x_set_border_width ();
638 void x_set_internal_border_width ();
639 void x_explicitly_set_name ();
640 void x_set_autoraise ();
641 void x_set_autolower ();
642 void x_set_vertical_scroll_bars ();
643 void x_set_visibility ();
644 void x_set_menu_bar_lines ();
645 void x_set_scroll_bar_width ();
646 void x_set_unsplittable ();
647
648 static struct x_frame_parm_table x_frame_parms[] =
649 {
650 "foreground-color", x_set_foreground_color,
651 "background-color", x_set_background_color,
652 "mouse-color", x_set_mouse_color,
653 "cursor-color", x_set_cursor_color,
654 "border-color", x_set_border_color,
655 "cursor-type", x_set_cursor_type,
656 "icon-type", x_set_icon_type,
657 "font", x_set_font,
658 "border-width", x_set_border_width,
659 "internal-border-width", x_set_internal_border_width,
660 "name", x_explicitly_set_name,
661 "auto-raise", x_set_autoraise,
662 "auto-lower", x_set_autolower,
663 "vertical-scroll-bars", x_set_vertical_scroll_bars,
664 "visibility", x_set_visibility,
665 "menu-bar-lines", x_set_menu_bar_lines,
666 "scroll-bar-width", x_set_scroll_bar_width,
667 "unsplittable", x_set_unsplittable,
668 };
669
670 /* Attach the `x-frame-parameter' properties to
671 the Lisp symbol names of parameters relevant to X. */
672
673 init_x_parm_symbols ()
674 {
675 int i;
676
677 for (i = 0; i < sizeof (x_frame_parms) / sizeof (x_frame_parms[0]); i++)
678 Fput (intern (x_frame_parms[i].name), Qx_frame_parameter,
679 make_number (i));
680 }
681 \f
682 /* Change the parameters of FRAME as specified by ALIST.
683 If a parameter is not specially recognized, do nothing;
684 otherwise call the `x_set_...' function for that parameter. */
685
686 void
687 x_set_frame_parameters (f, alist)
688 FRAME_PTR f;
689 Lisp_Object alist;
690 {
691 Lisp_Object tail;
692
693 /* If both of these parameters are present, it's more efficient to
694 set them both at once. So we wait until we've looked at the
695 entire list before we set them. */
696 Lisp_Object width, height;
697
698 /* Same here. */
699 Lisp_Object left, top;
700
701 /* Same with these. */
702 Lisp_Object icon_left, icon_top;
703
704 /* Record in these vectors all the parms specified. */
705 Lisp_Object *parms;
706 Lisp_Object *values;
707 int i;
708 int left_no_change = 0, top_no_change = 0;
709 int icon_left_no_change = 0, icon_top_no_change = 0;
710
711 i = 0;
712 for (tail = alist; CONSP (tail); tail = Fcdr (tail))
713 i++;
714
715 parms = (Lisp_Object *) alloca (i * sizeof (Lisp_Object));
716 values = (Lisp_Object *) alloca (i * sizeof (Lisp_Object));
717
718 /* Extract parm names and values into those vectors. */
719
720 i = 0;
721 for (tail = alist; CONSP (tail); tail = Fcdr (tail))
722 {
723 Lisp_Object elt, prop, val;
724
725 elt = Fcar (tail);
726 parms[i] = Fcar (elt);
727 values[i] = Fcdr (elt);
728 i++;
729 }
730
731 width = height = top = left = Qunbound;
732 icon_left = icon_top = Qunbound;
733
734 /* Now process them in reverse of specified order. */
735 for (i--; i >= 0; i--)
736 {
737 Lisp_Object prop, val;
738
739 prop = parms[i];
740 val = values[i];
741
742 if (EQ (prop, Qwidth))
743 width = val;
744 else if (EQ (prop, Qheight))
745 height = val;
746 else if (EQ (prop, Qtop))
747 top = val;
748 else if (EQ (prop, Qleft))
749 left = val;
750 else if (EQ (prop, Qicon_top))
751 icon_top = val;
752 else if (EQ (prop, Qicon_left))
753 icon_left = val;
754 else
755 {
756 register Lisp_Object param_index, old_value;
757
758 param_index = Fget (prop, Qx_frame_parameter);
759 old_value = get_frame_param (f, prop);
760 store_frame_param (f, prop, val);
761 if (NATNUMP (param_index)
762 && (XFASTINT (param_index)
763 < sizeof (x_frame_parms)/sizeof (x_frame_parms[0])))
764 (*x_frame_parms[XINT (param_index)].setter)(f, val, old_value);
765 }
766 }
767
768 /* Don't die if just one of these was set. */
769 if (EQ (left, Qunbound))
770 {
771 left_no_change = 1;
772 if (f->display.x->left_pos < 0)
773 left = Fcons (Qplus, Fcons (make_number (f->display.x->left_pos), Qnil));
774 else
775 XSETINT (left, f->display.x->left_pos);
776 }
777 if (EQ (top, Qunbound))
778 {
779 top_no_change = 1;
780 if (f->display.x->top_pos < 0)
781 top = Fcons (Qplus, Fcons (make_number (f->display.x->top_pos), Qnil));
782 else
783 XSETINT (top, f->display.x->top_pos);
784 }
785
786 /* If one of the icon positions was not set, preserve or default it. */
787 if (EQ (icon_left, Qunbound) || ! INTEGERP (icon_left))
788 {
789 icon_left_no_change = 1;
790 icon_left = Fcdr (Fassq (Qicon_left, f->param_alist));
791 if (NILP (icon_left))
792 XSETINT (icon_left, 0);
793 }
794 if (EQ (icon_top, Qunbound) || ! INTEGERP (icon_top))
795 {
796 icon_top_no_change = 1;
797 icon_top = Fcdr (Fassq (Qicon_top, f->param_alist));
798 if (NILP (icon_top))
799 XSETINT (icon_top, 0);
800 }
801
802 /* Don't die if just one of these was set. */
803 if (EQ (width, Qunbound))
804 XSETINT (width, FRAME_WIDTH (f));
805 if (EQ (height, Qunbound))
806 XSETINT (height, FRAME_HEIGHT (f));
807
808 /* Don't set these parameters these unless they've been explicitly
809 specified. The window might be mapped or resized while we're in
810 this function, and we don't want to override that unless the lisp
811 code has asked for it.
812
813 Don't set these parameters unless they actually differ from the
814 window's current parameters; the window may not actually exist
815 yet. */
816 {
817 Lisp_Object frame;
818
819 check_frame_size (f, &height, &width);
820
821 XSETFRAME (frame, f);
822
823 if ((NUMBERP (width) && XINT (width) != FRAME_WIDTH (f))
824 || (NUMBERP (height) && XINT (height) != FRAME_HEIGHT (f)))
825 Fset_frame_size (frame, width, height);
826
827 if ((!NILP (left) || !NILP (top))
828 && ! (left_no_change && top_no_change)
829 && ! (NUMBERP (left) && XINT (left) == f->display.x->left_pos
830 && NUMBERP (top) && XINT (top) == f->display.x->top_pos))
831 {
832 int leftpos = 0;
833 int toppos = 0;
834
835 /* Record the signs. */
836 f->display.x->size_hint_flags &= ~ (XNegative | YNegative);
837 if (EQ (left, Qminus))
838 f->display.x->size_hint_flags |= XNegative;
839 else if (INTEGERP (left))
840 {
841 leftpos = XINT (left);
842 if (leftpos < 0)
843 f->display.x->size_hint_flags |= XNegative;
844 }
845 else if (CONSP (left) && EQ (XCONS (left)->car, Qminus)
846 && CONSP (XCONS (left)->cdr)
847 && INTEGERP (XCONS (XCONS (left)->cdr)->car))
848 {
849 leftpos = - XINT (XCONS (XCONS (left)->cdr)->car);
850 f->display.x->size_hint_flags |= XNegative;
851 }
852 else if (CONSP (left) && EQ (XCONS (left)->car, Qplus)
853 && CONSP (XCONS (left)->cdr)
854 && INTEGERP (XCONS (XCONS (left)->cdr)->car))
855 {
856 leftpos = XINT (XCONS (XCONS (left)->cdr)->car);
857 }
858
859 if (EQ (top, Qminus))
860 f->display.x->size_hint_flags |= YNegative;
861 else if (INTEGERP (top))
862 {
863 toppos = XINT (top);
864 if (toppos < 0)
865 f->display.x->size_hint_flags |= YNegative;
866 }
867 else if (CONSP (top) && EQ (XCONS (top)->car, Qminus)
868 && CONSP (XCONS (top)->cdr)
869 && INTEGERP (XCONS (XCONS (top)->cdr)->car))
870 {
871 toppos = - XINT (XCONS (XCONS (top)->cdr)->car);
872 f->display.x->size_hint_flags |= YNegative;
873 }
874 else if (CONSP (top) && EQ (XCONS (top)->car, Qplus)
875 && CONSP (XCONS (top)->cdr)
876 && INTEGERP (XCONS (XCONS (top)->cdr)->car))
877 {
878 toppos = XINT (XCONS (XCONS (top)->cdr)->car);
879 }
880
881
882 /* Store the numeric value of the position. */
883 f->display.x->top_pos = toppos;
884 f->display.x->left_pos = leftpos;
885
886 f->display.x->win_gravity = NorthWestGravity;
887
888 /* Actually set that position, and convert to absolute. */
889 x_set_offset (f, leftpos, toppos, 0);
890 }
891
892 if ((!NILP (icon_left) || !NILP (icon_top))
893 && ! (icon_left_no_change && icon_top_no_change))
894 x_wm_set_icon_position (f, XINT (icon_left), XINT (icon_top));
895 }
896 }
897
898 /* Store the screen positions of frame F into XPTR and YPTR.
899 These are the positions of the containing window manager window,
900 not Emacs's own window. */
901
902 void
903 x_real_positions (f, xptr, yptr)
904 FRAME_PTR f;
905 int *xptr, *yptr;
906 {
907 int win_x, win_y;
908 Window child;
909
910 /* This is pretty gross, but seems to be the easiest way out of
911 the problem that arises when restarting window-managers. */
912
913 #ifdef USE_X_TOOLKIT
914 Window outer = XtWindow (f->display.x->widget);
915 #else
916 Window outer = f->display.x->window_desc;
917 #endif
918 Window tmp_root_window;
919 Window *tmp_children;
920 int tmp_nchildren;
921
922 x_catch_errors (FRAME_X_DISPLAY (f));
923 while (1)
924 {
925 XQueryTree (FRAME_X_DISPLAY (f), outer, &tmp_root_window,
926 &f->display.x->parent_desc,
927 &tmp_children, &tmp_nchildren);
928 xfree (tmp_children);
929
930 win_x = win_y = 0;
931
932 /* Find the position of the outside upper-left corner of
933 the inner window, with respect to the outer window. */
934 if (f->display.x->parent_desc != FRAME_X_DISPLAY_INFO (f)->root_window)
935 {
936 XTranslateCoordinates (FRAME_X_DISPLAY (f),
937
938 /* From-window, to-window. */
939 #ifdef USE_X_TOOLKIT
940 XtWindow (f->display.x->widget),
941 #else
942 f->display.x->window_desc,
943 #endif
944 f->display.x->parent_desc,
945
946 /* From-position, to-position. */
947 0, 0, &win_x, &win_y,
948
949 /* Child of win. */
950 &child);
951
952 win_x += f->display.x->border_width;
953 win_y += f->display.x->border_width;
954 }
955
956 /* It is possible for the window returned by the XQueryNotify
957 to become invalid by the time we call XTranslateCoordinates.
958 That can happen when you restart some window managers.
959 If so, we get an error in XTranslateCoordinates.
960 Detect that and try the whole thing over. */
961 if (! x_had_errors_p (FRAME_X_DISPLAY (f)))
962 break;
963 }
964
965 x_uncatch_errors (FRAME_X_DISPLAY (f));
966
967 *xptr = f->display.x->left_pos - win_x;
968 *yptr = f->display.x->top_pos - win_y;
969 }
970
971 /* Insert a description of internally-recorded parameters of frame X
972 into the parameter alist *ALISTPTR that is to be given to the user.
973 Only parameters that are specific to the X window system
974 and whose values are not correctly recorded in the frame's
975 param_alist need to be considered here. */
976
977 x_report_frame_params (f, alistptr)
978 struct frame *f;
979 Lisp_Object *alistptr;
980 {
981 char buf[16];
982
983 store_in_alist (alistptr, Qleft, make_number (f->display.x->left_pos));
984 store_in_alist (alistptr, Qtop, make_number (f->display.x->top_pos));
985 store_in_alist (alistptr, Qborder_width,
986 make_number (f->display.x->border_width));
987 store_in_alist (alistptr, Qinternal_border_width,
988 make_number (f->display.x->internal_border_width));
989 sprintf (buf, "%ld", (long) FRAME_X_WINDOW (f));
990 store_in_alist (alistptr, Qwindow_id,
991 build_string (buf));
992 FRAME_SAMPLE_VISIBILITY (f);
993 store_in_alist (alistptr, Qvisibility,
994 (FRAME_VISIBLE_P (f) ? Qt
995 : FRAME_ICONIFIED_P (f) ? Qicon : Qnil));
996 store_in_alist (alistptr, Qdisplay,
997 XCONS (FRAME_X_DISPLAY_INFO (f)->name_list_element)->car);
998 }
999 \f
1000
1001 /* Decide if color named COLOR is valid for the display associated with
1002 the selected frame; if so, return the rgb values in COLOR_DEF.
1003 If ALLOC is nonzero, allocate a new colormap cell. */
1004
1005 int
1006 defined_color (f, color, color_def, alloc)
1007 FRAME_PTR f;
1008 char *color;
1009 XColor *color_def;
1010 int alloc;
1011 {
1012 register int status;
1013 Colormap screen_colormap;
1014 Display *display = FRAME_X_DISPLAY (f);
1015
1016 BLOCK_INPUT;
1017 screen_colormap = DefaultColormap (display, XDefaultScreen (display));
1018
1019 status = XParseColor (display, screen_colormap, color, color_def);
1020 if (status && alloc)
1021 {
1022 status = XAllocColor (display, screen_colormap, color_def);
1023 if (!status)
1024 {
1025 /* If we got to this point, the colormap is full, so we're
1026 going to try and get the next closest color.
1027 The algorithm used is a least-squares matching, which is
1028 what X uses for closest color matching with StaticColor visuals. */
1029
1030 XColor *cells;
1031 int no_cells;
1032 int nearest;
1033 long nearest_delta, trial_delta;
1034 int x;
1035
1036 no_cells = XDisplayCells (display, XDefaultScreen (display));
1037 cells = (XColor *) alloca (sizeof (XColor) * no_cells);
1038
1039 for (x = 0; x < no_cells; x++)
1040 cells[x].pixel = x;
1041
1042 XQueryColors (display, screen_colormap, cells, no_cells);
1043 nearest = 0;
1044 /* I'm assuming CSE so I'm not going to condense this. */
1045 nearest_delta = ((((color_def->red >> 8) - (cells[0].red >> 8))
1046 * ((color_def->red >> 8) - (cells[0].red >> 8)))
1047 +
1048 (((color_def->green >> 8) - (cells[0].green >> 8))
1049 * ((color_def->green >> 8) - (cells[0].green >> 8)))
1050 +
1051 (((color_def->blue >> 8) - (cells[0].blue >> 8))
1052 * ((color_def->blue >> 8) - (cells[0].blue >> 8))));
1053 for (x = 1; x < no_cells; x++)
1054 {
1055 trial_delta = ((((color_def->red >> 8) - (cells[x].red >> 8))
1056 * ((color_def->red >> 8) - (cells[x].red >> 8)))
1057 +
1058 (((color_def->green >> 8) - (cells[x].green >> 8))
1059 * ((color_def->green >> 8) - (cells[x].green >> 8)))
1060 +
1061 (((color_def->blue >> 8) - (cells[x].blue >> 8))
1062 * ((color_def->blue >> 8) - (cells[x].blue >> 8))));
1063 if (trial_delta < nearest_delta)
1064 {
1065 nearest = x;
1066 nearest_delta = trial_delta;
1067 }
1068 }
1069 color_def->red = cells[nearest].red;
1070 color_def->green = cells[nearest].green;
1071 color_def->blue = cells[nearest].blue;
1072 status = XAllocColor (display, screen_colormap, color_def);
1073 }
1074 }
1075 UNBLOCK_INPUT;
1076
1077 if (status)
1078 return 1;
1079 else
1080 return 0;
1081 }
1082
1083 /* Given a string ARG naming a color, compute a pixel value from it
1084 suitable for screen F.
1085 If F is not a color screen, return DEF (default) regardless of what
1086 ARG says. */
1087
1088 int
1089 x_decode_color (f, arg, def)
1090 FRAME_PTR f;
1091 Lisp_Object arg;
1092 int def;
1093 {
1094 XColor cdef;
1095
1096 CHECK_STRING (arg, 0);
1097
1098 if (strcmp (XSTRING (arg)->data, "black") == 0)
1099 return BLACK_PIX_DEFAULT (f);
1100 else if (strcmp (XSTRING (arg)->data, "white") == 0)
1101 return WHITE_PIX_DEFAULT (f);
1102
1103 if (FRAME_X_DISPLAY_INFO (f)->n_planes == 1)
1104 return def;
1105
1106 /* defined_color is responsible for coping with failures
1107 by looking for a near-miss. */
1108 if (defined_color (f, XSTRING (arg)->data, &cdef, 1))
1109 return cdef.pixel;
1110
1111 /* defined_color failed; return an ultimate default. */
1112 return def;
1113 }
1114 \f
1115 /* Functions called only from `x_set_frame_param'
1116 to set individual parameters.
1117
1118 If FRAME_X_WINDOW (f) is 0,
1119 the frame is being created and its X-window does not exist yet.
1120 In that case, just record the parameter's new value
1121 in the standard place; do not attempt to change the window. */
1122
1123 void
1124 x_set_foreground_color (f, arg, oldval)
1125 struct frame *f;
1126 Lisp_Object arg, oldval;
1127 {
1128 f->display.x->foreground_pixel
1129 = x_decode_color (f, arg, BLACK_PIX_DEFAULT (f));
1130 if (FRAME_X_WINDOW (f) != 0)
1131 {
1132 BLOCK_INPUT;
1133 XSetForeground (FRAME_X_DISPLAY (f), f->display.x->normal_gc,
1134 f->display.x->foreground_pixel);
1135 XSetBackground (FRAME_X_DISPLAY (f), f->display.x->reverse_gc,
1136 f->display.x->foreground_pixel);
1137 UNBLOCK_INPUT;
1138 recompute_basic_faces (f);
1139 if (FRAME_VISIBLE_P (f))
1140 redraw_frame (f);
1141 }
1142 }
1143
1144 void
1145 x_set_background_color (f, arg, oldval)
1146 struct frame *f;
1147 Lisp_Object arg, oldval;
1148 {
1149 Pixmap temp;
1150 int mask;
1151
1152 f->display.x->background_pixel
1153 = x_decode_color (f, arg, WHITE_PIX_DEFAULT (f));
1154
1155 if (FRAME_X_WINDOW (f) != 0)
1156 {
1157 BLOCK_INPUT;
1158 /* The main frame area. */
1159 XSetBackground (FRAME_X_DISPLAY (f), f->display.x->normal_gc,
1160 f->display.x->background_pixel);
1161 XSetForeground (FRAME_X_DISPLAY (f), f->display.x->reverse_gc,
1162 f->display.x->background_pixel);
1163 XSetForeground (FRAME_X_DISPLAY (f), f->display.x->cursor_gc,
1164 f->display.x->background_pixel);
1165 XSetWindowBackground (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
1166 f->display.x->background_pixel);
1167 {
1168 Lisp_Object bar;
1169 for (bar = FRAME_SCROLL_BARS (f); !NILP (bar);
1170 bar = XSCROLL_BAR (bar)->next)
1171 XSetWindowBackground (FRAME_X_DISPLAY (f),
1172 SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar)),
1173 f->display.x->background_pixel);
1174 }
1175 UNBLOCK_INPUT;
1176
1177 recompute_basic_faces (f);
1178
1179 if (FRAME_VISIBLE_P (f))
1180 redraw_frame (f);
1181 }
1182 }
1183
1184 void
1185 x_set_mouse_color (f, arg, oldval)
1186 struct frame *f;
1187 Lisp_Object arg, oldval;
1188 {
1189 Cursor cursor, nontext_cursor, mode_cursor, cross_cursor;
1190 int mask_color;
1191
1192 if (!EQ (Qnil, arg))
1193 f->display.x->mouse_pixel
1194 = x_decode_color (f, arg, BLACK_PIX_DEFAULT (f));
1195 mask_color = f->display.x->background_pixel;
1196 /* No invisible pointers. */
1197 if (mask_color == f->display.x->mouse_pixel
1198 && mask_color == f->display.x->background_pixel)
1199 f->display.x->mouse_pixel = f->display.x->foreground_pixel;
1200
1201 BLOCK_INPUT;
1202
1203 /* It's not okay to crash if the user selects a screwy cursor. */
1204 x_catch_errors (FRAME_X_DISPLAY (f));
1205
1206 if (!EQ (Qnil, Vx_pointer_shape))
1207 {
1208 CHECK_NUMBER (Vx_pointer_shape, 0);
1209 cursor = XCreateFontCursor (FRAME_X_DISPLAY (f), XINT (Vx_pointer_shape));
1210 }
1211 else
1212 cursor = XCreateFontCursor (FRAME_X_DISPLAY (f), XC_xterm);
1213 x_check_errors (FRAME_X_DISPLAY (f), "bad text pointer cursor: %s");
1214
1215 if (!EQ (Qnil, Vx_nontext_pointer_shape))
1216 {
1217 CHECK_NUMBER (Vx_nontext_pointer_shape, 0);
1218 nontext_cursor = XCreateFontCursor (FRAME_X_DISPLAY (f),
1219 XINT (Vx_nontext_pointer_shape));
1220 }
1221 else
1222 nontext_cursor = XCreateFontCursor (FRAME_X_DISPLAY (f), XC_left_ptr);
1223 x_check_errors (FRAME_X_DISPLAY (f), "bad nontext pointer cursor: %s");
1224
1225 if (!EQ (Qnil, Vx_mode_pointer_shape))
1226 {
1227 CHECK_NUMBER (Vx_mode_pointer_shape, 0);
1228 mode_cursor = XCreateFontCursor (FRAME_X_DISPLAY (f),
1229 XINT (Vx_mode_pointer_shape));
1230 }
1231 else
1232 mode_cursor = XCreateFontCursor (FRAME_X_DISPLAY (f), XC_xterm);
1233 x_check_errors (FRAME_X_DISPLAY (f), "bad modeline pointer cursor: %s");
1234
1235 if (!EQ (Qnil, Vx_sensitive_text_pointer_shape))
1236 {
1237 CHECK_NUMBER (Vx_sensitive_text_pointer_shape, 0);
1238 cross_cursor
1239 = XCreateFontCursor (FRAME_X_DISPLAY (f),
1240 XINT (Vx_sensitive_text_pointer_shape));
1241 }
1242 else
1243 cross_cursor = XCreateFontCursor (FRAME_X_DISPLAY (f), XC_crosshair);
1244
1245 /* Check and report errors with the above calls. */
1246 x_check_errors (FRAME_X_DISPLAY (f), "can't set cursor shape: %s");
1247 x_uncatch_errors (FRAME_X_DISPLAY (f));
1248
1249 {
1250 XColor fore_color, back_color;
1251
1252 fore_color.pixel = f->display.x->mouse_pixel;
1253 back_color.pixel = mask_color;
1254 XQueryColor (FRAME_X_DISPLAY (f),
1255 DefaultColormap (FRAME_X_DISPLAY (f),
1256 DefaultScreen (FRAME_X_DISPLAY (f))),
1257 &fore_color);
1258 XQueryColor (FRAME_X_DISPLAY (f),
1259 DefaultColormap (FRAME_X_DISPLAY (f),
1260 DefaultScreen (FRAME_X_DISPLAY (f))),
1261 &back_color);
1262 XRecolorCursor (FRAME_X_DISPLAY (f), cursor,
1263 &fore_color, &back_color);
1264 XRecolorCursor (FRAME_X_DISPLAY (f), nontext_cursor,
1265 &fore_color, &back_color);
1266 XRecolorCursor (FRAME_X_DISPLAY (f), mode_cursor,
1267 &fore_color, &back_color);
1268 XRecolorCursor (FRAME_X_DISPLAY (f), cross_cursor,
1269 &fore_color, &back_color);
1270 }
1271
1272 if (FRAME_X_WINDOW (f) != 0)
1273 {
1274 XDefineCursor (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), cursor);
1275 }
1276
1277 if (cursor != f->display.x->text_cursor && f->display.x->text_cursor != 0)
1278 XFreeCursor (FRAME_X_DISPLAY (f), f->display.x->text_cursor);
1279 f->display.x->text_cursor = cursor;
1280
1281 if (nontext_cursor != f->display.x->nontext_cursor
1282 && f->display.x->nontext_cursor != 0)
1283 XFreeCursor (FRAME_X_DISPLAY (f), f->display.x->nontext_cursor);
1284 f->display.x->nontext_cursor = nontext_cursor;
1285
1286 if (mode_cursor != f->display.x->modeline_cursor
1287 && f->display.x->modeline_cursor != 0)
1288 XFreeCursor (FRAME_X_DISPLAY (f), f->display.x->modeline_cursor);
1289 f->display.x->modeline_cursor = mode_cursor;
1290 if (cross_cursor != f->display.x->cross_cursor
1291 && f->display.x->cross_cursor != 0)
1292 XFreeCursor (FRAME_X_DISPLAY (f), f->display.x->cross_cursor);
1293 f->display.x->cross_cursor = cross_cursor;
1294
1295 XFlush (FRAME_X_DISPLAY (f));
1296 UNBLOCK_INPUT;
1297 }
1298
1299 void
1300 x_set_cursor_color (f, arg, oldval)
1301 struct frame *f;
1302 Lisp_Object arg, oldval;
1303 {
1304 unsigned long fore_pixel;
1305
1306 if (!EQ (Vx_cursor_fore_pixel, Qnil))
1307 fore_pixel = x_decode_color (f, Vx_cursor_fore_pixel,
1308 WHITE_PIX_DEFAULT (f));
1309 else
1310 fore_pixel = f->display.x->background_pixel;
1311 f->display.x->cursor_pixel = x_decode_color (f, arg, BLACK_PIX_DEFAULT (f));
1312
1313 /* Make sure that the cursor color differs from the background color. */
1314 if (f->display.x->cursor_pixel == f->display.x->background_pixel)
1315 {
1316 f->display.x->cursor_pixel = f->display.x->mouse_pixel;
1317 if (f->display.x->cursor_pixel == fore_pixel)
1318 fore_pixel = f->display.x->background_pixel;
1319 }
1320 f->display.x->cursor_foreground_pixel = fore_pixel;
1321
1322 if (FRAME_X_WINDOW (f) != 0)
1323 {
1324 BLOCK_INPUT;
1325 XSetBackground (FRAME_X_DISPLAY (f), f->display.x->cursor_gc,
1326 f->display.x->cursor_pixel);
1327 XSetForeground (FRAME_X_DISPLAY (f), f->display.x->cursor_gc,
1328 fore_pixel);
1329 UNBLOCK_INPUT;
1330
1331 if (FRAME_VISIBLE_P (f))
1332 {
1333 x_display_cursor (f, 0);
1334 x_display_cursor (f, 1);
1335 }
1336 }
1337 }
1338
1339 /* Set the border-color of frame F to value described by ARG.
1340 ARG can be a string naming a color.
1341 The border-color is used for the border that is drawn by the X server.
1342 Note that this does not fully take effect if done before
1343 F has an x-window; it must be redone when the window is created.
1344
1345 Note: this is done in two routines because of the way X10 works.
1346
1347 Note: under X11, this is normally the province of the window manager,
1348 and so emacs' border colors may be overridden. */
1349
1350 void
1351 x_set_border_color (f, arg, oldval)
1352 struct frame *f;
1353 Lisp_Object arg, oldval;
1354 {
1355 unsigned char *str;
1356 int pix;
1357
1358 CHECK_STRING (arg, 0);
1359 str = XSTRING (arg)->data;
1360
1361 pix = x_decode_color (f, arg, BLACK_PIX_DEFAULT (f));
1362
1363 x_set_border_pixel (f, pix);
1364 }
1365
1366 /* Set the border-color of frame F to pixel value PIX.
1367 Note that this does not fully take effect if done before
1368 F has an x-window. */
1369
1370 x_set_border_pixel (f, pix)
1371 struct frame *f;
1372 int pix;
1373 {
1374 f->display.x->border_pixel = pix;
1375
1376 if (FRAME_X_WINDOW (f) != 0 && f->display.x->border_width > 0)
1377 {
1378 Pixmap temp;
1379 int mask;
1380
1381 BLOCK_INPUT;
1382 XSetWindowBorder (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
1383 pix);
1384 UNBLOCK_INPUT;
1385
1386 if (FRAME_VISIBLE_P (f))
1387 redraw_frame (f);
1388 }
1389 }
1390
1391 void
1392 x_set_cursor_type (f, arg, oldval)
1393 FRAME_PTR f;
1394 Lisp_Object arg, oldval;
1395 {
1396 if (EQ (arg, Qbar))
1397 {
1398 FRAME_DESIRED_CURSOR (f) = bar_cursor;
1399 f->display.x->cursor_width = 2;
1400 }
1401 else if (CONSP (arg) && EQ (XCONS (arg)->car, Qbar)
1402 && INTEGERP (XCONS (arg)->cdr))
1403 {
1404 FRAME_DESIRED_CURSOR (f) = bar_cursor;
1405 f->display.x->cursor_width = XINT (XCONS (arg)->cdr);
1406 }
1407 else
1408 /* Treat anything unknown as "box cursor".
1409 It was bad to signal an error; people have trouble fixing
1410 .Xdefaults with Emacs, when it has something bad in it. */
1411 FRAME_DESIRED_CURSOR (f) = filled_box_cursor;
1412
1413 /* Make sure the cursor gets redrawn. This is overkill, but how
1414 often do people change cursor types? */
1415 update_mode_lines++;
1416 }
1417
1418 void
1419 x_set_icon_type (f, arg, oldval)
1420 struct frame *f;
1421 Lisp_Object arg, oldval;
1422 {
1423 Lisp_Object tem;
1424 int result;
1425
1426 if (STRINGP (arg))
1427 {
1428 if (STRINGP (oldval) && EQ (Fstring_equal (oldval, arg), Qt))
1429 return;
1430 }
1431 else if (!STRINGP (oldval) && EQ (oldval, Qnil) == EQ (arg, Qnil))
1432 return;
1433
1434 BLOCK_INPUT;
1435 if (NILP (arg))
1436 result = x_text_icon (f, 0);
1437 else
1438 result = x_bitmap_icon (f, arg);
1439
1440 if (result)
1441 {
1442 UNBLOCK_INPUT;
1443 error ("No icon window available");
1444 }
1445
1446 /* If the window was unmapped (and its icon was mapped),
1447 the new icon is not mapped, so map the window in its stead. */
1448 if (FRAME_VISIBLE_P (f))
1449 {
1450 #ifdef USE_X_TOOLKIT
1451 XtPopup (f->display.x->widget, XtGrabNone);
1452 #endif
1453 XMapWindow (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f));
1454 }
1455
1456 XFlush (FRAME_X_DISPLAY (f));
1457 UNBLOCK_INPUT;
1458 }
1459
1460 /* Return non-nil if frame F wants a bitmap icon. */
1461
1462 Lisp_Object
1463 x_icon_type (f)
1464 FRAME_PTR f;
1465 {
1466 Lisp_Object tem;
1467
1468 tem = assq_no_quit (Qicon_type, f->param_alist);
1469 if (CONSP (tem))
1470 return XCONS (tem)->cdr;
1471 else
1472 return Qnil;
1473 }
1474
1475 extern Lisp_Object x_new_font ();
1476
1477 void
1478 x_set_font (f, arg, oldval)
1479 struct frame *f;
1480 Lisp_Object arg, oldval;
1481 {
1482 Lisp_Object result;
1483
1484 CHECK_STRING (arg, 1);
1485
1486 BLOCK_INPUT;
1487 result = x_new_font (f, XSTRING (arg)->data);
1488 UNBLOCK_INPUT;
1489
1490 if (EQ (result, Qnil))
1491 error ("Font \"%s\" is not defined", XSTRING (arg)->data);
1492 else if (EQ (result, Qt))
1493 error ("the characters of the given font have varying widths");
1494 else if (STRINGP (result))
1495 {
1496 recompute_basic_faces (f);
1497 store_frame_param (f, Qfont, result);
1498 }
1499 else
1500 abort ();
1501 }
1502
1503 void
1504 x_set_border_width (f, arg, oldval)
1505 struct frame *f;
1506 Lisp_Object arg, oldval;
1507 {
1508 CHECK_NUMBER (arg, 0);
1509
1510 if (XINT (arg) == f->display.x->border_width)
1511 return;
1512
1513 if (FRAME_X_WINDOW (f) != 0)
1514 error ("Cannot change the border width of a window");
1515
1516 f->display.x->border_width = XINT (arg);
1517 }
1518
1519 void
1520 x_set_internal_border_width (f, arg, oldval)
1521 struct frame *f;
1522 Lisp_Object arg, oldval;
1523 {
1524 int mask;
1525 int old = f->display.x->internal_border_width;
1526
1527 CHECK_NUMBER (arg, 0);
1528 f->display.x->internal_border_width = XINT (arg);
1529 if (f->display.x->internal_border_width < 0)
1530 f->display.x->internal_border_width = 0;
1531
1532 if (f->display.x->internal_border_width == old)
1533 return;
1534
1535 if (FRAME_X_WINDOW (f) != 0)
1536 {
1537 BLOCK_INPUT;
1538 x_set_window_size (f, 0, f->width, f->height);
1539 #if 0
1540 x_set_resize_hint (f);
1541 #endif
1542 XFlush (FRAME_X_DISPLAY (f));
1543 UNBLOCK_INPUT;
1544 SET_FRAME_GARBAGED (f);
1545 }
1546 }
1547
1548 void
1549 x_set_visibility (f, value, oldval)
1550 struct frame *f;
1551 Lisp_Object value, oldval;
1552 {
1553 Lisp_Object frame;
1554 XSETFRAME (frame, f);
1555
1556 if (NILP (value))
1557 Fmake_frame_invisible (frame, Qt);
1558 else if (EQ (value, Qicon))
1559 Ficonify_frame (frame);
1560 else
1561 Fmake_frame_visible (frame);
1562 }
1563
1564 static void
1565 x_set_menu_bar_lines_1 (window, n)
1566 Lisp_Object window;
1567 int n;
1568 {
1569 struct window *w = XWINDOW (window);
1570
1571 XSETFASTINT (w->top, XFASTINT (w->top) + n);
1572 XSETFASTINT (w->height, XFASTINT (w->height) - n);
1573
1574 /* Handle just the top child in a vertical split. */
1575 if (!NILP (w->vchild))
1576 x_set_menu_bar_lines_1 (w->vchild, n);
1577
1578 /* Adjust all children in a horizontal split. */
1579 for (window = w->hchild; !NILP (window); window = w->next)
1580 {
1581 w = XWINDOW (window);
1582 x_set_menu_bar_lines_1 (window, n);
1583 }
1584 }
1585
1586 void
1587 x_set_menu_bar_lines (f, value, oldval)
1588 struct frame *f;
1589 Lisp_Object value, oldval;
1590 {
1591 int nlines;
1592 int olines = FRAME_MENU_BAR_LINES (f);
1593
1594 /* Right now, menu bars don't work properly in minibuf-only frames;
1595 most of the commands try to apply themselves to the minibuffer
1596 frame itslef, and get an error because you can't switch buffers
1597 in or split the minibuffer window. */
1598 if (FRAME_MINIBUF_ONLY_P (f))
1599 return;
1600
1601 if (INTEGERP (value))
1602 nlines = XINT (value);
1603 else
1604 nlines = 0;
1605
1606 #ifdef USE_X_TOOLKIT
1607 FRAME_MENU_BAR_LINES (f) = 0;
1608 if (nlines)
1609 FRAME_EXTERNAL_MENU_BAR (f) = 1;
1610 else
1611 {
1612 if (FRAME_EXTERNAL_MENU_BAR (f) == 1)
1613 free_frame_menubar (f);
1614 FRAME_EXTERNAL_MENU_BAR (f) = 0;
1615 f->display.x->menubar_widget = 0;
1616 }
1617 #else /* not USE_X_TOOLKIT */
1618 FRAME_MENU_BAR_LINES (f) = nlines;
1619 x_set_menu_bar_lines_1 (f->root_window, nlines - olines);
1620 #endif /* not USE_X_TOOLKIT */
1621 }
1622
1623 /* Change the name of frame F to NAME. If NAME is nil, set F's name to
1624 x_id_name.
1625
1626 If EXPLICIT is non-zero, that indicates that lisp code is setting the
1627 name; if NAME is a string, set F's name to NAME and set
1628 F->explicit_name; if NAME is Qnil, then clear F->explicit_name.
1629
1630 If EXPLICIT is zero, that indicates that Emacs redisplay code is
1631 suggesting a new name, which lisp code should override; if
1632 F->explicit_name is set, ignore the new name; otherwise, set it. */
1633
1634 void
1635 x_set_name (f, name, explicit)
1636 struct frame *f;
1637 Lisp_Object name;
1638 int explicit;
1639 {
1640 /* Make sure that requests from lisp code override requests from
1641 Emacs redisplay code. */
1642 if (explicit)
1643 {
1644 /* If we're switching from explicit to implicit, we had better
1645 update the mode lines and thereby update the title. */
1646 if (f->explicit_name && NILP (name))
1647 update_mode_lines = 1;
1648
1649 f->explicit_name = ! NILP (name);
1650 }
1651 else if (f->explicit_name)
1652 return;
1653
1654 /* If NAME is nil, set the name to the x_id_name. */
1655 if (NILP (name))
1656 {
1657 /* Check for no change needed in this very common case
1658 before we do any consing. */
1659 if (!strcmp (FRAME_X_DISPLAY_INFO (f)->x_id_name,
1660 XSTRING (f->name)->data))
1661 return;
1662 name = build_string (FRAME_X_DISPLAY_INFO (f)->x_id_name);
1663 }
1664 else
1665 CHECK_STRING (name, 0);
1666
1667 /* Don't change the name if it's already NAME. */
1668 if (! NILP (Fstring_equal (name, f->name)))
1669 return;
1670
1671 if (FRAME_X_WINDOW (f))
1672 {
1673 BLOCK_INPUT;
1674 #ifdef HAVE_X11R4
1675 {
1676 XTextProperty text;
1677 text.value = XSTRING (name)->data;
1678 text.encoding = XA_STRING;
1679 text.format = 8;
1680 text.nitems = XSTRING (name)->size;
1681 #ifdef USE_X_TOOLKIT
1682 XSetWMName (FRAME_X_DISPLAY (f),
1683 XtWindow (f->display.x->widget), &text);
1684 XSetWMIconName (FRAME_X_DISPLAY (f), XtWindow (f->display.x->widget),
1685 &text);
1686 #else /* not USE_X_TOOLKIT */
1687 XSetWMName (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), &text);
1688 XSetWMIconName (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), &text);
1689 #endif /* not USE_X_TOOLKIT */
1690 }
1691 #else /* not HAVE_X11R4 */
1692 XSetIconName (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
1693 XSTRING (name)->data);
1694 XStoreName (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
1695 XSTRING (name)->data);
1696 #endif /* not HAVE_X11R4 */
1697 UNBLOCK_INPUT;
1698 }
1699
1700 f->name = name;
1701 }
1702
1703 /* This function should be called when the user's lisp code has
1704 specified a name for the frame; the name will override any set by the
1705 redisplay code. */
1706 void
1707 x_explicitly_set_name (f, arg, oldval)
1708 FRAME_PTR f;
1709 Lisp_Object arg, oldval;
1710 {
1711 x_set_name (f, arg, 1);
1712 }
1713
1714 /* This function should be called by Emacs redisplay code to set the
1715 name; names set this way will never override names set by the user's
1716 lisp code. */
1717 void
1718 x_implicitly_set_name (f, arg, oldval)
1719 FRAME_PTR f;
1720 Lisp_Object arg, oldval;
1721 {
1722 x_set_name (f, arg, 0);
1723 }
1724
1725 void
1726 x_set_autoraise (f, arg, oldval)
1727 struct frame *f;
1728 Lisp_Object arg, oldval;
1729 {
1730 f->auto_raise = !EQ (Qnil, arg);
1731 }
1732
1733 void
1734 x_set_autolower (f, arg, oldval)
1735 struct frame *f;
1736 Lisp_Object arg, oldval;
1737 {
1738 f->auto_lower = !EQ (Qnil, arg);
1739 }
1740
1741 void
1742 x_set_unsplittable (f, arg, oldval)
1743 struct frame *f;
1744 Lisp_Object arg, oldval;
1745 {
1746 f->no_split = !NILP (arg);
1747 }
1748
1749 void
1750 x_set_vertical_scroll_bars (f, arg, oldval)
1751 struct frame *f;
1752 Lisp_Object arg, oldval;
1753 {
1754 if (NILP (arg) != ! FRAME_HAS_VERTICAL_SCROLL_BARS (f))
1755 {
1756 FRAME_HAS_VERTICAL_SCROLL_BARS (f) = ! NILP (arg);
1757
1758 /* We set this parameter before creating the X window for the
1759 frame, so we can get the geometry right from the start.
1760 However, if the window hasn't been created yet, we shouldn't
1761 call x_set_window_size. */
1762 if (FRAME_X_WINDOW (f))
1763 x_set_window_size (f, 0, FRAME_WIDTH (f), FRAME_HEIGHT (f));
1764 }
1765 }
1766
1767 void
1768 x_set_scroll_bar_width (f, arg, oldval)
1769 struct frame *f;
1770 Lisp_Object arg, oldval;
1771 {
1772 if (NILP (arg))
1773 {
1774 FRAME_SCROLL_BAR_PIXEL_WIDTH (f) = 0;
1775 FRAME_SCROLL_BAR_COLS (f) = 2;
1776 }
1777 else if (INTEGERP (arg) && XINT (arg) > 0
1778 && XFASTINT (arg) != FRAME_SCROLL_BAR_PIXEL_WIDTH (f))
1779 {
1780 int wid = FONT_WIDTH (f->display.x->font);
1781 FRAME_SCROLL_BAR_PIXEL_WIDTH (f) = XFASTINT (arg);
1782 FRAME_SCROLL_BAR_COLS (f) = (XFASTINT (arg) + wid-1) / wid;
1783 if (FRAME_X_WINDOW (f))
1784 x_set_window_size (f, 0, FRAME_WIDTH (f), FRAME_HEIGHT (f));
1785 }
1786 }
1787 \f
1788 /* Subroutines of creating an X frame. */
1789
1790 /* Make sure that Vx_resource_name is set to a reasonable value. */
1791 static void
1792 validate_x_resource_name ()
1793 {
1794 int len;
1795 /* Number of valid characters in the resource name. */
1796 int good_count = 0;
1797 /* Number of invalid characters in the resource name. */
1798 int bad_count = 0;
1799 Lisp_Object new;
1800 int i;
1801
1802 if (STRINGP (Vx_resource_name))
1803 {
1804 unsigned char *p = XSTRING (Vx_resource_name)->data;
1805 int i;
1806
1807 len = XSTRING (Vx_resource_name)->size;
1808
1809 /* Only letters, digits, - and _ are valid in resource names.
1810 Count the valid characters and count the invalid ones. */
1811 for (i = 0; i < len; i++)
1812 {
1813 int c = p[i];
1814 if (! ((c >= 'a' && c <= 'z')
1815 || (c >= 'A' && c <= 'Z')
1816 || (c >= '0' && c <= '9')
1817 || c == '-' || c == '_'))
1818 bad_count++;
1819 else
1820 good_count++;
1821 }
1822 }
1823 else
1824 /* Not a string => completely invalid. */
1825 bad_count = 5, good_count = 0;
1826
1827 /* If name is valid already, return. */
1828 if (bad_count == 0)
1829 return;
1830
1831 /* If name is entirely invalid, or nearly so, use `emacs'. */
1832 if (good_count == 0
1833 || (good_count == 1 && bad_count > 0))
1834 {
1835 Vx_resource_name = make_string ("emacs", 5);
1836 return;
1837 }
1838
1839 /* Name is partly valid. Copy it and replace the invalid characters
1840 with underscores. */
1841
1842 Vx_resource_name = new = Fcopy_sequence (Vx_resource_name);
1843
1844 for (i = 0; i < len; i++)
1845 {
1846 int c = XSTRING (new)->data[i];
1847 if (! ((c >= 'a' && c <= 'z')
1848 || (c >= 'A' && c <= 'Z')
1849 || (c >= '0' && c <= '9')
1850 || c == '-' || c == '_'))
1851 XSTRING (new)->data[i] = '_';
1852 }
1853 }
1854
1855
1856 extern char *x_get_string_resource ();
1857
1858 DEFUN ("x-get-resource", Fx_get_resource, Sx_get_resource, 2, 4, 0,
1859 "Return the value of ATTRIBUTE, of class CLASS, from the X defaults database.\n\
1860 This uses `INSTANCE.ATTRIBUTE' as the key and `Emacs.CLASS' as the\n\
1861 class, where INSTANCE is the name under which Emacs was invoked, or\n\
1862 the name specified by the `-name' or `-rn' command-line arguments.\n\
1863 \n\
1864 The optional arguments COMPONENT and SUBCLASS add to the key and the\n\
1865 class, respectively. You must specify both of them or neither.\n\
1866 If you specify them, the key is `INSTANCE.COMPONENT.ATTRIBUTE'\n\
1867 and the class is `Emacs.CLASS.SUBCLASS'.")
1868 (attribute, class, component, subclass)
1869 Lisp_Object attribute, class, component, subclass;
1870 {
1871 register char *value;
1872 char *name_key;
1873 char *class_key;
1874 Lisp_Object resname;
1875
1876 check_x ();
1877
1878 CHECK_STRING (attribute, 0);
1879 CHECK_STRING (class, 0);
1880
1881 if (!NILP (component))
1882 CHECK_STRING (component, 1);
1883 if (!NILP (subclass))
1884 CHECK_STRING (subclass, 2);
1885 if (NILP (component) != NILP (subclass))
1886 error ("x-get-resource: must specify both COMPONENT and SUBCLASS or neither");
1887
1888 validate_x_resource_name ();
1889 resname = Vx_resource_name;
1890
1891 if (NILP (component))
1892 {
1893 /* Allocate space for the components, the dots which separate them,
1894 and the final '\0'. */
1895 name_key = (char *) alloca (XSTRING (resname)->size
1896 + XSTRING (attribute)->size
1897 + 2);
1898 class_key = (char *) alloca ((sizeof (EMACS_CLASS) - 1)
1899 + XSTRING (class)->size
1900 + 2);
1901
1902 sprintf (name_key, "%s.%s",
1903 XSTRING (resname)->data,
1904 XSTRING (attribute)->data);
1905 sprintf (class_key, "%s.%s",
1906 EMACS_CLASS,
1907 XSTRING (class)->data);
1908 }
1909 else
1910 {
1911 name_key = (char *) alloca (XSTRING (resname)->size
1912 + XSTRING (component)->size
1913 + XSTRING (attribute)->size
1914 + 3);
1915
1916 class_key = (char *) alloca ((sizeof (EMACS_CLASS) - 1)
1917 + XSTRING (class)->size
1918 + XSTRING (subclass)->size
1919 + 3);
1920
1921 sprintf (name_key, "%s.%s.%s",
1922 XSTRING (resname)->data,
1923 XSTRING (component)->data,
1924 XSTRING (attribute)->data);
1925 sprintf (class_key, "%s.%s.%s",
1926 EMACS_CLASS,
1927 XSTRING (class)->data,
1928 XSTRING (subclass)->data);
1929 }
1930
1931 value = x_get_string_resource (check_x_display_info (Qnil)->xrdb,
1932 name_key, class_key);
1933
1934 if (value != (char *) 0)
1935 return build_string (value);
1936 else
1937 return Qnil;
1938 }
1939
1940 /* Used when C code wants a resource value. */
1941
1942 char *
1943 x_get_resource_string (attribute, class)
1944 char *attribute, *class;
1945 {
1946 register char *value;
1947 char *name_key;
1948 char *class_key;
1949
1950 /* Allocate space for the components, the dots which separate them,
1951 and the final '\0'. */
1952 name_key = (char *) alloca (XSTRING (Vinvocation_name)->size
1953 + strlen (attribute) + 2);
1954 class_key = (char *) alloca ((sizeof (EMACS_CLASS) - 1)
1955 + strlen (class) + 2);
1956
1957 sprintf (name_key, "%s.%s",
1958 XSTRING (Vinvocation_name)->data,
1959 attribute);
1960 sprintf (class_key, "%s.%s", EMACS_CLASS, class);
1961
1962 return x_get_string_resource (FRAME_X_DISPLAY_INFO (selected_frame)->xrdb,
1963 name_key, class_key);
1964 }
1965
1966 /* Types we might convert a resource string into. */
1967 enum resource_types
1968 {
1969 number, boolean, string, symbol
1970 };
1971
1972 /* Return the value of parameter PARAM.
1973
1974 First search ALIST, then Vdefault_frame_alist, then the X defaults
1975 database, using ATTRIBUTE as the attribute name and CLASS as its class.
1976
1977 Convert the resource to the type specified by desired_type.
1978
1979 If no default is specified, return Qunbound. If you call
1980 x_get_arg, make sure you deal with Qunbound in a reasonable way,
1981 and don't let it get stored in any Lisp-visible variables! */
1982
1983 static Lisp_Object
1984 x_get_arg (alist, param, attribute, class, type)
1985 Lisp_Object alist, param;
1986 char *attribute;
1987 char *class;
1988 enum resource_types type;
1989 {
1990 register Lisp_Object tem;
1991
1992 tem = Fassq (param, alist);
1993 if (EQ (tem, Qnil))
1994 tem = Fassq (param, Vdefault_frame_alist);
1995 if (EQ (tem, Qnil))
1996 {
1997
1998 if (attribute)
1999 {
2000 tem = Fx_get_resource (build_string (attribute),
2001 build_string (class),
2002 Qnil, Qnil);
2003
2004 if (NILP (tem))
2005 return Qunbound;
2006
2007 switch (type)
2008 {
2009 case number:
2010 return make_number (atoi (XSTRING (tem)->data));
2011
2012 case boolean:
2013 tem = Fdowncase (tem);
2014 if (!strcmp (XSTRING (tem)->data, "on")
2015 || !strcmp (XSTRING (tem)->data, "true"))
2016 return Qt;
2017 else
2018 return Qnil;
2019
2020 case string:
2021 return tem;
2022
2023 case symbol:
2024 /* As a special case, we map the values `true' and `on'
2025 to Qt, and `false' and `off' to Qnil. */
2026 {
2027 Lisp_Object lower;
2028 lower = Fdowncase (tem);
2029 if (!strcmp (XSTRING (lower)->data, "on")
2030 || !strcmp (XSTRING (lower)->data, "true"))
2031 return Qt;
2032 else if (!strcmp (XSTRING (lower)->data, "off")
2033 || !strcmp (XSTRING (lower)->data, "false"))
2034 return Qnil;
2035 else
2036 return Fintern (tem, Qnil);
2037 }
2038
2039 default:
2040 abort ();
2041 }
2042 }
2043 else
2044 return Qunbound;
2045 }
2046 return Fcdr (tem);
2047 }
2048
2049 /* Record in frame F the specified or default value according to ALIST
2050 of the parameter named PARAM (a Lisp symbol).
2051 If no value is specified for PARAM, look for an X default for XPROP
2052 on the frame named NAME.
2053 If that is not found either, use the value DEFLT. */
2054
2055 static Lisp_Object
2056 x_default_parameter (f, alist, prop, deflt, xprop, xclass, type)
2057 struct frame *f;
2058 Lisp_Object alist;
2059 Lisp_Object prop;
2060 Lisp_Object deflt;
2061 char *xprop;
2062 char *xclass;
2063 enum resource_types type;
2064 {
2065 Lisp_Object tem;
2066
2067 tem = x_get_arg (alist, prop, xprop, xclass, type);
2068 if (EQ (tem, Qunbound))
2069 tem = deflt;
2070 x_set_frame_parameters (f, Fcons (Fcons (prop, tem), Qnil));
2071 return tem;
2072 }
2073 \f
2074 DEFUN ("x-parse-geometry", Fx_parse_geometry, Sx_parse_geometry, 1, 1, 0,
2075 "Parse an X-style geometry string STRING.\n\
2076 Returns an alist of the form ((top . TOP), (left . LEFT) ... ).\n\
2077 The properties returned may include `top', `left', `height', and `width'.\n\
2078 The value of `left' or `top' may be an integer,\n\
2079 or a list (+ N) meaning N pixels relative to top/left corner,\n\
2080 or a list (- N) meaning -N pixels relative to bottom/right corner.")
2081 (string)
2082 Lisp_Object string;
2083 {
2084 int geometry, x, y;
2085 unsigned int width, height;
2086 Lisp_Object result;
2087
2088 CHECK_STRING (string, 0);
2089
2090 geometry = XParseGeometry ((char *) XSTRING (string)->data,
2091 &x, &y, &width, &height);
2092
2093 #if 0
2094 if (!!(geometry & XValue) != !!(geometry & YValue))
2095 error ("Must specify both x and y position, or neither");
2096 #endif
2097
2098 result = Qnil;
2099 if (geometry & XValue)
2100 {
2101 Lisp_Object element;
2102
2103 if (x >= 0 && (geometry & XNegative))
2104 element = Fcons (Qleft, Fcons (Qminus, Fcons (make_number (-x), Qnil)));
2105 else if (x < 0 && ! (geometry & XNegative))
2106 element = Fcons (Qleft, Fcons (Qplus, Fcons (make_number (x), Qnil)));
2107 else
2108 element = Fcons (Qleft, make_number (x));
2109 result = Fcons (element, result);
2110 }
2111
2112 if (geometry & YValue)
2113 {
2114 Lisp_Object element;
2115
2116 if (y >= 0 && (geometry & YNegative))
2117 element = Fcons (Qtop, Fcons (Qminus, Fcons (make_number (-y), Qnil)));
2118 else if (y < 0 && ! (geometry & YNegative))
2119 element = Fcons (Qtop, Fcons (Qplus, Fcons (make_number (y), Qnil)));
2120 else
2121 element = Fcons (Qtop, make_number (y));
2122 result = Fcons (element, result);
2123 }
2124
2125 if (geometry & WidthValue)
2126 result = Fcons (Fcons (Qwidth, make_number (width)), result);
2127 if (geometry & HeightValue)
2128 result = Fcons (Fcons (Qheight, make_number (height)), result);
2129
2130 return result;
2131 }
2132
2133 /* Calculate the desired size and position of this window,
2134 and return the flags saying which aspects were specified.
2135
2136 This function does not make the coordinates positive. */
2137
2138 #define DEFAULT_ROWS 40
2139 #define DEFAULT_COLS 80
2140
2141 static int
2142 x_figure_window_size (f, parms)
2143 struct frame *f;
2144 Lisp_Object parms;
2145 {
2146 register Lisp_Object tem0, tem1, tem2;
2147 int height, width, left, top;
2148 register int geometry;
2149 long window_prompting = 0;
2150
2151 /* Default values if we fall through.
2152 Actually, if that happens we should get
2153 window manager prompting. */
2154 f->width = DEFAULT_COLS;
2155 f->height = DEFAULT_ROWS;
2156 /* Window managers expect that if program-specified
2157 positions are not (0,0), they're intentional, not defaults. */
2158 f->display.x->top_pos = 0;
2159 f->display.x->left_pos = 0;
2160
2161 tem0 = x_get_arg (parms, Qheight, 0, 0, number);
2162 tem1 = x_get_arg (parms, Qwidth, 0, 0, number);
2163 tem2 = x_get_arg (parms, Quser_size, 0, 0, number);
2164 if (! EQ (tem0, Qunbound) || ! EQ (tem1, Qunbound))
2165 {
2166 if (!EQ (tem0, Qunbound))
2167 {
2168 CHECK_NUMBER (tem0, 0);
2169 f->height = XINT (tem0);
2170 }
2171 if (!EQ (tem1, Qunbound))
2172 {
2173 CHECK_NUMBER (tem1, 0);
2174 f->width = XINT (tem1);
2175 }
2176 if (!NILP (tem2) && !EQ (tem2, Qunbound))
2177 window_prompting |= USSize;
2178 else
2179 window_prompting |= PSize;
2180 }
2181
2182 f->display.x->vertical_scroll_bar_extra
2183 = (!FRAME_HAS_VERTICAL_SCROLL_BARS (f)
2184 ? 0
2185 : FRAME_SCROLL_BAR_PIXEL_WIDTH (f) > 0
2186 ? FRAME_SCROLL_BAR_PIXEL_WIDTH (f)
2187 : (FRAME_SCROLL_BAR_COLS (f) * FONT_WIDTH (f->display.x->font)));
2188 f->display.x->pixel_width = CHAR_TO_PIXEL_WIDTH (f, f->width);
2189 f->display.x->pixel_height = CHAR_TO_PIXEL_HEIGHT (f, f->height);
2190
2191 tem0 = x_get_arg (parms, Qtop, 0, 0, number);
2192 tem1 = x_get_arg (parms, Qleft, 0, 0, number);
2193 tem2 = x_get_arg (parms, Quser_position, 0, 0, number);
2194 if (! EQ (tem0, Qunbound) || ! EQ (tem1, Qunbound))
2195 {
2196 if (EQ (tem0, Qminus))
2197 {
2198 f->display.x->top_pos = 0;
2199 window_prompting |= YNegative;
2200 }
2201 else if (CONSP (tem0) && EQ (XCONS (tem0)->car, Qminus)
2202 && CONSP (XCONS (tem0)->cdr)
2203 && INTEGERP (XCONS (XCONS (tem0)->cdr)->car))
2204 {
2205 f->display.x->top_pos = - XINT (XCONS (XCONS (tem0)->cdr)->car);
2206 window_prompting |= YNegative;
2207 }
2208 else if (CONSP (tem0) && EQ (XCONS (tem0)->car, Qplus)
2209 && CONSP (XCONS (tem0)->cdr)
2210 && INTEGERP (XCONS (XCONS (tem0)->cdr)->car))
2211 {
2212 f->display.x->top_pos = XINT (XCONS (XCONS (tem0)->cdr)->car);
2213 }
2214 else if (EQ (tem0, Qunbound))
2215 f->display.x->top_pos = 0;
2216 else
2217 {
2218 CHECK_NUMBER (tem0, 0);
2219 f->display.x->top_pos = XINT (tem0);
2220 if (f->display.x->top_pos < 0)
2221 window_prompting |= YNegative;
2222 }
2223
2224 if (EQ (tem1, Qminus))
2225 {
2226 f->display.x->left_pos = 0;
2227 window_prompting |= XNegative;
2228 }
2229 else if (CONSP (tem1) && EQ (XCONS (tem1)->car, Qminus)
2230 && CONSP (XCONS (tem1)->cdr)
2231 && INTEGERP (XCONS (XCONS (tem1)->cdr)->car))
2232 {
2233 f->display.x->left_pos = - XINT (XCONS (XCONS (tem1)->cdr)->car);
2234 window_prompting |= XNegative;
2235 }
2236 else if (CONSP (tem1) && EQ (XCONS (tem1)->car, Qplus)
2237 && CONSP (XCONS (tem1)->cdr)
2238 && INTEGERP (XCONS (XCONS (tem1)->cdr)->car))
2239 {
2240 f->display.x->left_pos = XINT (XCONS (XCONS (tem1)->cdr)->car);
2241 }
2242 else if (EQ (tem1, Qunbound))
2243 f->display.x->left_pos = 0;
2244 else
2245 {
2246 CHECK_NUMBER (tem1, 0);
2247 f->display.x->left_pos = XINT (tem1);
2248 if (f->display.x->left_pos < 0)
2249 window_prompting |= XNegative;
2250 }
2251
2252 if (!NILP (tem2) && ! EQ (tem2, Qunbound))
2253 window_prompting |= USPosition;
2254 else
2255 window_prompting |= PPosition;
2256 }
2257
2258 return window_prompting;
2259 }
2260
2261 #if !defined (HAVE_X11R4) && !defined (HAVE_XSETWMPROTOCOLS)
2262
2263 Status
2264 XSetWMProtocols (dpy, w, protocols, count)
2265 Display *dpy;
2266 Window w;
2267 Atom *protocols;
2268 int count;
2269 {
2270 Atom prop;
2271 prop = XInternAtom (dpy, "WM_PROTOCOLS", False);
2272 if (prop == None) return False;
2273 XChangeProperty (dpy, w, prop, XA_ATOM, 32, PropModeReplace,
2274 (unsigned char *) protocols, count);
2275 return True;
2276 }
2277 #endif /* not HAVE_X11R4 && not HAVE_XSETWMPROTOCOLS */
2278 \f
2279 #ifdef USE_X_TOOLKIT
2280
2281 /* If the WM_PROTOCOLS property does not already contain WM_TAKE_FOCUS,
2282 WM_DELETE_WINDOW, and WM_SAVE_YOURSELF, then add them. (They may
2283 already be present because of the toolkit (Motif adds some of them,
2284 for example, but Xt doesn't). */
2285
2286 static void
2287 hack_wm_protocols (f, widget)
2288 FRAME_PTR f;
2289 Widget widget;
2290 {
2291 Display *dpy = XtDisplay (widget);
2292 Window w = XtWindow (widget);
2293 int need_delete = 1;
2294 int need_focus = 1;
2295 int need_save = 1;
2296
2297 BLOCK_INPUT;
2298 {
2299 Atom type, *atoms = 0;
2300 int format = 0;
2301 unsigned long nitems = 0;
2302 unsigned long bytes_after;
2303
2304 if (Success == XGetWindowProperty (dpy, w,
2305 FRAME_X_DISPLAY_INFO (f)->Xatom_wm_protocols,
2306 0, 100, False, XA_ATOM,
2307 &type, &format, &nitems, &bytes_after,
2308 (unsigned char **) &atoms)
2309 && format == 32 && type == XA_ATOM)
2310 while (nitems > 0)
2311 {
2312 nitems--;
2313 if (atoms[nitems] == FRAME_X_DISPLAY_INFO (f)->Xatom_wm_delete_window)
2314 need_delete = 0;
2315 else if (atoms[nitems] == FRAME_X_DISPLAY_INFO (f)->Xatom_wm_take_focus)
2316 need_focus = 0;
2317 else if (atoms[nitems] == FRAME_X_DISPLAY_INFO (f)->Xatom_wm_save_yourself)
2318 need_save = 0;
2319 }
2320 if (atoms) XFree ((char *) atoms);
2321 }
2322 {
2323 Atom props [10];
2324 int count = 0;
2325 if (need_delete)
2326 props[count++] = FRAME_X_DISPLAY_INFO (f)->Xatom_wm_delete_window;
2327 if (need_focus)
2328 props[count++] = FRAME_X_DISPLAY_INFO (f)->Xatom_wm_take_focus;
2329 if (need_save)
2330 props[count++] = FRAME_X_DISPLAY_INFO (f)->Xatom_wm_save_yourself;
2331 if (count)
2332 XChangeProperty (dpy, w, FRAME_X_DISPLAY_INFO (f)->Xatom_wm_protocols,
2333 XA_ATOM, 32, PropModeAppend,
2334 (unsigned char *) props, count);
2335 }
2336 UNBLOCK_INPUT;
2337 }
2338 #endif
2339 \f
2340 #ifdef USE_X_TOOLKIT
2341
2342 /* Create and set up the X widget for frame F. */
2343
2344 static void
2345 x_window (f, window_prompting, minibuffer_only)
2346 struct frame *f;
2347 long window_prompting;
2348 int minibuffer_only;
2349 {
2350 XClassHint class_hints;
2351 XSetWindowAttributes attributes;
2352 unsigned long attribute_mask;
2353
2354 Widget shell_widget;
2355 Widget pane_widget;
2356 Widget frame_widget;
2357 Arg al [25];
2358 int ac;
2359
2360 BLOCK_INPUT;
2361
2362 {
2363 char *str
2364 = (STRINGP (f->name) ? (char *)XSTRING (f->name)->data : "emacs");
2365 f->namebuf = (char *) xrealloc (f->namebuf, strlen (str) + 1);
2366 strcpy (f->namebuf, str);
2367 }
2368
2369 ac = 0;
2370 XtSetArg (al[ac], XtNallowShellResize, 1); ac++;
2371 XtSetArg (al[ac], XtNinput, 1); ac++;
2372 XtSetArg (al[ac], XtNmappedWhenManaged, 0); ac++;
2373 shell_widget = XtAppCreateShell (f->namebuf, EMACS_CLASS,
2374 topLevelShellWidgetClass,
2375 FRAME_X_DISPLAY (f), al, ac);
2376
2377 f->display.x->widget = shell_widget;
2378 /* maybe_set_screen_title_format (shell_widget); */
2379
2380 pane_widget = lw_create_widget ("main", "pane", widget_id_tick++,
2381 (widget_value *) NULL,
2382 shell_widget, False,
2383 (lw_callback) NULL,
2384 (lw_callback) NULL,
2385 (lw_callback) NULL);
2386
2387 f->display.x->column_widget = pane_widget;
2388
2389 if (!minibuffer_only && FRAME_EXTERNAL_MENU_BAR (f))
2390 initialize_frame_menubar (f);
2391
2392 /* mappedWhenManaged to false tells to the paned window to not map/unmap
2393 the emacs screen when changing menubar. This reduces flickering. */
2394
2395 ac = 0;
2396 XtSetArg (al[ac], XtNmappedWhenManaged, 0); ac++;
2397 XtSetArg (al[ac], XtNshowGrip, 0); ac++;
2398 XtSetArg (al[ac], XtNallowResize, 1); ac++;
2399 XtSetArg (al[ac], XtNresizeToPreferred, 1); ac++;
2400 XtSetArg (al[ac], XtNemacsFrame, f); ac++;
2401 frame_widget = XtCreateWidget (f->namebuf,
2402 emacsFrameClass,
2403 pane_widget, al, ac);
2404 lw_set_main_areas (pane_widget, f->display.x->menubar_widget, frame_widget);
2405
2406 f->display.x->edit_widget = frame_widget;
2407
2408 if (f->display.x->menubar_widget)
2409 XtManageChild (f->display.x->menubar_widget);
2410 XtManageChild (frame_widget);
2411
2412 /* Do some needed geometry management. */
2413 {
2414 int len;
2415 char *tem, shell_position[32];
2416 Arg al[2];
2417 int ac = 0;
2418 int menubar_size
2419 = (f->display.x->menubar_widget
2420 ? (f->display.x->menubar_widget->core.height
2421 + f->display.x->menubar_widget->core.border_width)
2422 : 0);
2423
2424 if (FRAME_EXTERNAL_MENU_BAR (f))
2425 {
2426 Dimension ibw = 0;
2427 XtVaGetValues (pane_widget, XtNinternalBorderWidth, &ibw, NULL);
2428 menubar_size += ibw;
2429 }
2430
2431 /* Convert our geometry parameters into a geometry string
2432 and specify it.
2433 Note that we do not specify here whether the position
2434 is a user-specified or program-specified one.
2435 We pass that information later, in x_wm_set_size_hints. */
2436 {
2437 int left = f->display.x->left_pos;
2438 int xneg = window_prompting & XNegative;
2439 int top = f->display.x->top_pos;
2440 int yneg = window_prompting & YNegative;
2441 if (xneg)
2442 left = -left;
2443 if (yneg)
2444 top = -top;
2445 sprintf (shell_position, "=%dx%d%c%d%c%d", PIXEL_WIDTH (f),
2446 PIXEL_HEIGHT (f) + menubar_size,
2447 (xneg ? '-' : '+'), left,
2448 (yneg ? '-' : '+'), top);
2449 }
2450
2451 len = strlen (shell_position) + 1;
2452 tem = (char *) xmalloc (len);
2453 strncpy (tem, shell_position, len);
2454 XtSetArg (al[ac], XtNgeometry, tem); ac++;
2455 XtSetValues (shell_widget, al, ac);
2456 }
2457
2458 x_calc_absolute_position (f);
2459
2460 XtManageChild (pane_widget);
2461 XtRealizeWidget (shell_widget);
2462
2463 FRAME_X_WINDOW (f) = XtWindow (frame_widget);
2464
2465 validate_x_resource_name ();
2466 class_hints.res_name = (char *) XSTRING (Vx_resource_name)->data;
2467 class_hints.res_class = EMACS_CLASS;
2468 XSetClassHint (FRAME_X_DISPLAY (f), XtWindow (shell_widget), &class_hints);
2469
2470 f->display.x->wm_hints.input = True;
2471 f->display.x->wm_hints.flags |= InputHint;
2472 XSetWMHints (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
2473 &f->display.x->wm_hints);
2474
2475 hack_wm_protocols (f, shell_widget);
2476
2477 #ifdef HACK_EDITRES
2478 XtAddEventHandler (shell_widget, 0, True, _XEditResCheckMessages, 0);
2479 #endif
2480
2481 /* Do a stupid property change to force the server to generate a
2482 propertyNotify event so that the event_stream server timestamp will
2483 be initialized to something relevant to the time we created the window.
2484 */
2485 XChangeProperty (XtDisplay (frame_widget), XtWindow (frame_widget),
2486 FRAME_X_DISPLAY_INFO (f)->Xatom_wm_protocols,
2487 XA_ATOM, 32, PropModeAppend,
2488 (unsigned char*) NULL, 0);
2489
2490 /* Make all the standard events reach the Emacs frame. */
2491 attributes.event_mask = STANDARD_EVENT_SET;
2492 attribute_mask = CWEventMask;
2493 XChangeWindowAttributes (XtDisplay (shell_widget), XtWindow (shell_widget),
2494 attribute_mask, &attributes);
2495
2496 XtMapWidget (frame_widget);
2497
2498 /* x_set_name normally ignores requests to set the name if the
2499 requested name is the same as the current name. This is the one
2500 place where that assumption isn't correct; f->name is set, but
2501 the X server hasn't been told. */
2502 {
2503 Lisp_Object name;
2504 int explicit = f->explicit_name;
2505
2506 f->explicit_name = 0;
2507 name = f->name;
2508 f->name = Qnil;
2509 x_set_name (f, name, explicit);
2510 }
2511
2512 XDefineCursor (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
2513 f->display.x->text_cursor);
2514
2515 UNBLOCK_INPUT;
2516
2517 if (FRAME_X_WINDOW (f) == 0)
2518 error ("Unable to create window");
2519 }
2520
2521 #else /* not USE_X_TOOLKIT */
2522
2523 /* Create and set up the X window for frame F. */
2524
2525 x_window (f)
2526 struct frame *f;
2527
2528 {
2529 XClassHint class_hints;
2530 XSetWindowAttributes attributes;
2531 unsigned long attribute_mask;
2532
2533 attributes.background_pixel = f->display.x->background_pixel;
2534 attributes.border_pixel = f->display.x->border_pixel;
2535 attributes.bit_gravity = StaticGravity;
2536 attributes.backing_store = NotUseful;
2537 attributes.save_under = True;
2538 attributes.event_mask = STANDARD_EVENT_SET;
2539 attribute_mask = (CWBackPixel | CWBorderPixel | CWBitGravity
2540 #if 0
2541 | CWBackingStore | CWSaveUnder
2542 #endif
2543 | CWEventMask);
2544
2545 BLOCK_INPUT;
2546 FRAME_X_WINDOW (f)
2547 = XCreateWindow (FRAME_X_DISPLAY (f),
2548 f->display.x->parent_desc,
2549 f->display.x->left_pos,
2550 f->display.x->top_pos,
2551 PIXEL_WIDTH (f), PIXEL_HEIGHT (f),
2552 f->display.x->border_width,
2553 CopyFromParent, /* depth */
2554 InputOutput, /* class */
2555 FRAME_X_DISPLAY_INFO (f)->visual,
2556 attribute_mask, &attributes);
2557
2558 validate_x_resource_name ();
2559 class_hints.res_name = (char *) XSTRING (Vx_resource_name)->data;
2560 class_hints.res_class = EMACS_CLASS;
2561 XSetClassHint (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), &class_hints);
2562
2563 /* This indicates that we use the "Passive Input" input model.
2564 Unless we do this, we don't get the Focus{In,Out} events that we
2565 need to draw the cursor correctly. Accursed bureaucrats.
2566 XWhipsAndChains (FRAME_X_DISPLAY (f), IronMaiden, &TheRack); */
2567
2568 f->display.x->wm_hints.input = True;
2569 f->display.x->wm_hints.flags |= InputHint;
2570 XSetWMHints (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
2571 &f->display.x->wm_hints);
2572
2573 /* Request "save yourself" and "delete window" commands from wm. */
2574 {
2575 Atom protocols[2];
2576 protocols[0] = FRAME_X_DISPLAY_INFO (f)->Xatom_wm_delete_window;
2577 protocols[1] = FRAME_X_DISPLAY_INFO (f)->Xatom_wm_save_yourself;
2578 XSetWMProtocols (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), protocols, 2);
2579 }
2580
2581 /* x_set_name normally ignores requests to set the name if the
2582 requested name is the same as the current name. This is the one
2583 place where that assumption isn't correct; f->name is set, but
2584 the X server hasn't been told. */
2585 {
2586 Lisp_Object name;
2587 int explicit = f->explicit_name;
2588
2589 f->explicit_name = 0;
2590 name = f->name;
2591 f->name = Qnil;
2592 x_set_name (f, name, explicit);
2593 }
2594
2595 XDefineCursor (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
2596 f->display.x->text_cursor);
2597
2598 UNBLOCK_INPUT;
2599
2600 if (FRAME_X_WINDOW (f) == 0)
2601 error ("Unable to create window");
2602 }
2603
2604 #endif /* not USE_X_TOOLKIT */
2605
2606 /* Handle the icon stuff for this window. Perhaps later we might
2607 want an x_set_icon_position which can be called interactively as
2608 well. */
2609
2610 static void
2611 x_icon (f, parms)
2612 struct frame *f;
2613 Lisp_Object parms;
2614 {
2615 Lisp_Object icon_x, icon_y;
2616
2617 /* Set the position of the icon. Note that twm groups all
2618 icons in an icon window. */
2619 icon_x = x_get_arg (parms, Qicon_left, 0, 0, number);
2620 icon_y = x_get_arg (parms, Qicon_top, 0, 0, number);
2621 if (!EQ (icon_x, Qunbound) && !EQ (icon_y, Qunbound))
2622 {
2623 CHECK_NUMBER (icon_x, 0);
2624 CHECK_NUMBER (icon_y, 0);
2625 }
2626 else if (!EQ (icon_x, Qunbound) || !EQ (icon_y, Qunbound))
2627 error ("Both left and top icon corners of icon must be specified");
2628
2629 BLOCK_INPUT;
2630
2631 if (! EQ (icon_x, Qunbound))
2632 x_wm_set_icon_position (f, XINT (icon_x), XINT (icon_y));
2633
2634 /* Start up iconic or window? */
2635 x_wm_set_window_state
2636 (f, (EQ (x_get_arg (parms, Qvisibility, 0, 0, symbol), Qicon)
2637 ? IconicState
2638 : NormalState));
2639
2640 UNBLOCK_INPUT;
2641 }
2642
2643 /* Make the GC's needed for this window, setting the
2644 background, border and mouse colors; also create the
2645 mouse cursor and the gray border tile. */
2646
2647 static char cursor_bits[] =
2648 {
2649 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2650 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2651 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2652 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
2653 };
2654
2655 static void
2656 x_make_gc (f)
2657 struct frame *f;
2658 {
2659 XGCValues gc_values;
2660 GC temp_gc;
2661 XImage tileimage;
2662
2663 BLOCK_INPUT;
2664
2665 /* Create the GC's of this frame.
2666 Note that many default values are used. */
2667
2668 /* Normal video */
2669 gc_values.font = f->display.x->font->fid;
2670 gc_values.foreground = f->display.x->foreground_pixel;
2671 gc_values.background = f->display.x->background_pixel;
2672 gc_values.line_width = 0; /* Means 1 using fast algorithm. */
2673 f->display.x->normal_gc = XCreateGC (FRAME_X_DISPLAY (f),
2674 FRAME_X_WINDOW (f),
2675 GCLineWidth | GCFont
2676 | GCForeground | GCBackground,
2677 &gc_values);
2678
2679 /* Reverse video style. */
2680 gc_values.foreground = f->display.x->background_pixel;
2681 gc_values.background = f->display.x->foreground_pixel;
2682 f->display.x->reverse_gc = XCreateGC (FRAME_X_DISPLAY (f),
2683 FRAME_X_WINDOW (f),
2684 GCFont | GCForeground | GCBackground
2685 | GCLineWidth,
2686 &gc_values);
2687
2688 /* Cursor has cursor-color background, background-color foreground. */
2689 gc_values.foreground = f->display.x->background_pixel;
2690 gc_values.background = f->display.x->cursor_pixel;
2691 gc_values.fill_style = FillOpaqueStippled;
2692 gc_values.stipple
2693 = XCreateBitmapFromData (FRAME_X_DISPLAY (f),
2694 FRAME_X_DISPLAY_INFO (f)->root_window,
2695 cursor_bits, 16, 16);
2696 f->display.x->cursor_gc
2697 = XCreateGC (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
2698 (GCFont | GCForeground | GCBackground
2699 | GCFillStyle | GCStipple | GCLineWidth),
2700 &gc_values);
2701
2702 /* Create the gray border tile used when the pointer is not in
2703 the frame. Since this depends on the frame's pixel values,
2704 this must be done on a per-frame basis. */
2705 f->display.x->border_tile
2706 = (XCreatePixmapFromBitmapData
2707 (FRAME_X_DISPLAY (f), FRAME_X_DISPLAY_INFO (f)->root_window,
2708 gray_bits, gray_width, gray_height,
2709 f->display.x->foreground_pixel,
2710 f->display.x->background_pixel,
2711 DefaultDepth (FRAME_X_DISPLAY (f),
2712 XScreenNumberOfScreen (FRAME_X_SCREEN (f)))));
2713
2714 UNBLOCK_INPUT;
2715 }
2716
2717 DEFUN ("x-create-frame", Fx_create_frame, Sx_create_frame,
2718 1, 1, 0,
2719 "Make a new X window, which is called a \"frame\" in Emacs terms.\n\
2720 Returns an Emacs frame object.\n\
2721 ALIST is an alist of frame parameters.\n\
2722 If the parameters specify that the frame should not have a minibuffer,\n\
2723 and do not specify a specific minibuffer window to use,\n\
2724 then `default-minibuffer-frame' must be a frame whose minibuffer can\n\
2725 be shared by the new frame.\n\
2726 \n\
2727 This function is an internal primitive--use `make-frame' instead.")
2728 (parms)
2729 Lisp_Object parms;
2730 {
2731 struct frame *f;
2732 Lisp_Object frame, tem;
2733 Lisp_Object name;
2734 int minibuffer_only = 0;
2735 long window_prompting = 0;
2736 int width, height;
2737 int count = specpdl_ptr - specpdl;
2738 struct gcpro gcpro1;
2739 Lisp_Object display;
2740 struct x_display_info *dpyinfo;
2741 Lisp_Object parent;
2742
2743 check_x ();
2744
2745 display = x_get_arg (parms, Qdisplay, 0, 0, 0);
2746 if (EQ (display, Qunbound))
2747 display = Qnil;
2748 dpyinfo = check_x_display_info (display);
2749
2750 name = x_get_arg (parms, Qname, "title", "Title", string);
2751 if (!STRINGP (name)
2752 && ! EQ (name, Qunbound)
2753 && ! NILP (name))
2754 error ("Invalid frame name--not a string or nil");
2755
2756 /* See if parent window is specified. */
2757 parent = x_get_arg (parms, Qparent_id, NULL, NULL, number);
2758 if (EQ (parent, Qunbound))
2759 parent = Qnil;
2760 if (! NILP (parent))
2761 CHECK_NUMBER (parent, 0);
2762
2763 tem = x_get_arg (parms, Qminibuffer, 0, 0, symbol);
2764 if (EQ (tem, Qnone) || NILP (tem))
2765 f = make_frame_without_minibuffer (Qnil);
2766 else if (EQ (tem, Qonly))
2767 {
2768 f = make_minibuffer_frame ();
2769 minibuffer_only = 1;
2770 }
2771 else if (WINDOWP (tem))
2772 f = make_frame_without_minibuffer (tem);
2773 else
2774 f = make_frame (1);
2775
2776 /* Note that X Windows does support scroll bars. */
2777 FRAME_CAN_HAVE_SCROLL_BARS (f) = 1;
2778
2779 XSETFRAME (frame, f);
2780 GCPRO1 (frame);
2781
2782 f->output_method = output_x_window;
2783 f->display.x = (struct x_display *) xmalloc (sizeof (struct x_display));
2784 bzero (f->display.x, sizeof (struct x_display));
2785 f->display.x->icon_bitmap = -1;
2786
2787 FRAME_X_DISPLAY_INFO (f) = dpyinfo;
2788 #ifdef MULTI_KBOARD
2789 FRAME_KBOARD (f) = dpyinfo->kboard;
2790 #endif
2791
2792 /* Specify the parent under which to make this X window. */
2793
2794 if (!NILP (parent))
2795 {
2796 f->display.x->parent_desc = parent;
2797 f->display.x->explicit_parent = 1;
2798 }
2799 else
2800 {
2801 f->display.x->parent_desc = FRAME_X_DISPLAY_INFO (f)->root_window;
2802 f->display.x->explicit_parent = 0;
2803 }
2804
2805 /* Note that the frame has no physical cursor right now. */
2806 f->phys_cursor_x = -1;
2807
2808 /* Set the name; the functions to which we pass f expect the name to
2809 be set. */
2810 if (EQ (name, Qunbound) || NILP (name))
2811 {
2812 f->name = build_string (dpyinfo->x_id_name);
2813 f->explicit_name = 0;
2814 }
2815 else
2816 {
2817 f->name = name;
2818 f->explicit_name = 1;
2819 /* use the frame's title when getting resources for this frame. */
2820 specbind (Qx_resource_name, name);
2821 }
2822
2823 /* Extract the window parameters from the supplied values
2824 that are needed to determine window geometry. */
2825 {
2826 Lisp_Object font;
2827
2828 font = x_get_arg (parms, Qfont, "font", "Font", string);
2829 BLOCK_INPUT;
2830 /* First, try whatever font the caller has specified. */
2831 if (STRINGP (font))
2832 font = x_new_font (f, XSTRING (font)->data);
2833 /* Try out a font which we hope has bold and italic variations. */
2834 if (!STRINGP (font))
2835 font = x_new_font (f, "-misc-fixed-medium-r-normal-*-*-140-*-*-c-*-iso8859-1");
2836 if (! STRINGP (font))
2837 font = x_new_font (f, "-*-*-medium-r-normal-*-*-140-*-*-c-*-iso8859-1");
2838 if (! STRINGP (font))
2839 /* This was formerly the first thing tried, but it finds too many fonts
2840 and takes too long. */
2841 font = x_new_font (f, "-*-*-medium-r-*-*-*-*-*-*-c-*-iso8859-1");
2842 /* If those didn't work, look for something which will at least work. */
2843 if (! STRINGP (font))
2844 font = x_new_font (f, "-*-fixed-*-*-*-*-*-140-*-*-c-*-iso8859-1");
2845 UNBLOCK_INPUT;
2846 if (! STRINGP (font))
2847 font = build_string ("fixed");
2848
2849 x_default_parameter (f, parms, Qfont, font,
2850 "font", "Font", string);
2851 }
2852
2853 #ifdef USE_X_TOOLKIT
2854 /* Prevent lwlib/xlwmenu.c from crashing because of a bug
2855 whereby it fails to get any font. */
2856 xlwmenu_default_font = f->display.x->font;
2857 #endif
2858
2859 x_default_parameter (f, parms, Qborder_width, make_number (2),
2860 "borderwidth", "BorderWidth", number);
2861 /* This defaults to 2 in order to match xterm. We recognize either
2862 internalBorderWidth or internalBorder (which is what xterm calls
2863 it). */
2864 if (NILP (Fassq (Qinternal_border_width, parms)))
2865 {
2866 Lisp_Object value;
2867
2868 value = x_get_arg (parms, Qinternal_border_width,
2869 "internalBorder", "BorderWidth", number);
2870 if (! EQ (value, Qunbound))
2871 parms = Fcons (Fcons (Qinternal_border_width, value),
2872 parms);
2873 }
2874 x_default_parameter (f, parms, Qinternal_border_width, make_number (2),
2875 "internalBorderWidth", "BorderWidth", number);
2876 x_default_parameter (f, parms, Qvertical_scroll_bars, Qt,
2877 "verticalScrollBars", "ScrollBars", boolean);
2878
2879 /* Also do the stuff which must be set before the window exists. */
2880 x_default_parameter (f, parms, Qforeground_color, build_string ("black"),
2881 "foreground", "Foreground", string);
2882 x_default_parameter (f, parms, Qbackground_color, build_string ("white"),
2883 "background", "Background", string);
2884 x_default_parameter (f, parms, Qmouse_color, build_string ("black"),
2885 "pointerColor", "Foreground", string);
2886 x_default_parameter (f, parms, Qcursor_color, build_string ("black"),
2887 "cursorColor", "Foreground", string);
2888 x_default_parameter (f, parms, Qborder_color, build_string ("black"),
2889 "borderColor", "BorderColor", string);
2890
2891 x_default_parameter (f, parms, Qmenu_bar_lines, make_number (1),
2892 "menuBar", "MenuBar", number);
2893 x_default_parameter (f, parms, Qscroll_bar_width, Qnil,
2894 "scrollBarWidth", "ScrollBarWidth", number);
2895
2896 f->display.x->parent_desc = FRAME_X_DISPLAY_INFO (f)->root_window;
2897 window_prompting = x_figure_window_size (f, parms);
2898
2899 if (window_prompting & XNegative)
2900 {
2901 if (window_prompting & YNegative)
2902 f->display.x->win_gravity = SouthEastGravity;
2903 else
2904 f->display.x->win_gravity = NorthEastGravity;
2905 }
2906 else
2907 {
2908 if (window_prompting & YNegative)
2909 f->display.x->win_gravity = SouthWestGravity;
2910 else
2911 f->display.x->win_gravity = NorthWestGravity;
2912 }
2913
2914 f->display.x->size_hint_flags = window_prompting;
2915
2916 #ifdef USE_X_TOOLKIT
2917 x_window (f, window_prompting, minibuffer_only);
2918 #else
2919 x_window (f);
2920 #endif
2921 x_icon (f, parms);
2922 x_make_gc (f);
2923 init_frame_faces (f);
2924
2925 /* We need to do this after creating the X window, so that the
2926 icon-creation functions can say whose icon they're describing. */
2927 x_default_parameter (f, parms, Qicon_type, Qnil,
2928 "bitmapIcon", "BitmapIcon", symbol);
2929
2930 x_default_parameter (f, parms, Qauto_raise, Qnil,
2931 "autoRaise", "AutoRaiseLower", boolean);
2932 x_default_parameter (f, parms, Qauto_lower, Qnil,
2933 "autoLower", "AutoRaiseLower", boolean);
2934 x_default_parameter (f, parms, Qcursor_type, Qbox,
2935 "cursorType", "CursorType", symbol);
2936
2937 /* Dimensions, especially f->height, must be done via change_frame_size.
2938 Change will not be effected unless different from the current
2939 f->height. */
2940 width = f->width;
2941 height = f->height;
2942 f->height = f->width = 0;
2943 change_frame_size (f, height, width, 1, 0);
2944
2945 /* Tell the server what size and position, etc, we want,
2946 and how badly we want them. */
2947 BLOCK_INPUT;
2948 x_wm_set_size_hint (f, window_prompting, 0);
2949 UNBLOCK_INPUT;
2950
2951 tem = x_get_arg (parms, Qunsplittable, 0, 0, boolean);
2952 f->no_split = minibuffer_only || EQ (tem, Qt);
2953
2954 UNGCPRO;
2955
2956 /* It is now ok to make the frame official
2957 even if we get an error below.
2958 And the frame needs to be on Vframe_list
2959 or making it visible won't work. */
2960 Vframe_list = Fcons (frame, Vframe_list);
2961
2962 /* Now that the frame is official, it counts as a reference to
2963 its display. */
2964 FRAME_X_DISPLAY_INFO (f)->reference_count++;
2965
2966 /* Make the window appear on the frame and enable display,
2967 unless the caller says not to. However, with explicit parent,
2968 Emacs cannot control visibility, so don't try. */
2969 if (! f->display.x->explicit_parent)
2970 {
2971 Lisp_Object visibility;
2972
2973 visibility = x_get_arg (parms, Qvisibility, 0, 0, symbol);
2974 if (EQ (visibility, Qunbound))
2975 visibility = Qt;
2976
2977 if (EQ (visibility, Qicon))
2978 x_iconify_frame (f);
2979 else if (! NILP (visibility))
2980 x_make_frame_visible (f);
2981 else
2982 /* Must have been Qnil. */
2983 ;
2984 }
2985
2986 return unbind_to (count, frame);
2987 }
2988
2989 /* FRAME is used only to get a handle on the X display. We don't pass the
2990 display info directly because we're called from frame.c, which doesn't
2991 know about that structure. */
2992 Lisp_Object
2993 x_get_focus_frame (frame)
2994 struct frame *frame;
2995 {
2996 struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (frame);
2997 Lisp_Object xfocus;
2998 if (! dpyinfo->x_focus_frame)
2999 return Qnil;
3000
3001 XSETFRAME (xfocus, dpyinfo->x_focus_frame);
3002 return xfocus;
3003 }
3004
3005 DEFUN ("focus-frame", Ffocus_frame, Sfocus_frame, 1, 1, 0,
3006 "Set the focus on FRAME.")
3007 (frame)
3008 Lisp_Object frame;
3009 {
3010 CHECK_LIVE_FRAME (frame, 0);
3011
3012 if (FRAME_X_P (XFRAME (frame)))
3013 {
3014 BLOCK_INPUT;
3015 x_focus_on_frame (XFRAME (frame));
3016 UNBLOCK_INPUT;
3017 return frame;
3018 }
3019
3020 return Qnil;
3021 }
3022
3023 DEFUN ("unfocus-frame", Funfocus_frame, Sunfocus_frame, 0, 0, 0,
3024 "If a frame has been focused, release it.")
3025 ()
3026 {
3027 struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (selected_frame);
3028 if (dpyinfo->x_focus_frame)
3029 {
3030 BLOCK_INPUT;
3031 x_unfocus_frame (dpyinfo->x_focus_frame);
3032 UNBLOCK_INPUT;
3033 }
3034
3035 return Qnil;
3036 }
3037 \f
3038 DEFUN ("x-list-fonts", Fx_list_fonts, Sx_list_fonts, 1, 3, 0,
3039 "Return a list of the names of available fonts matching PATTERN.\n\
3040 If optional arguments FACE and FRAME are specified, return only fonts\n\
3041 the same size as FACE on FRAME.\n\
3042 \n\
3043 PATTERN is a string, perhaps with wildcard characters;\n\
3044 the * character matches any substring, and\n\
3045 the ? character matches any single character.\n\
3046 PATTERN is case-insensitive.\n\
3047 FACE is a face name--a symbol.\n\
3048 \n\
3049 The return value is a list of strings, suitable as arguments to\n\
3050 set-face-font.\n\
3051 \n\
3052 Fonts Emacs can't use (i.e. proportional fonts) may or may not be excluded\n\
3053 even if they match PATTERN and FACE.")
3054 (pattern, face, frame)
3055 Lisp_Object pattern, face, frame;
3056 {
3057 int num_fonts;
3058 char **names;
3059 #ifndef BROKEN_XLISTFONTSWITHINFO
3060 XFontStruct *info;
3061 #endif
3062 XFontStruct *size_ref;
3063 Lisp_Object list;
3064 FRAME_PTR f;
3065
3066 check_x ();
3067 CHECK_STRING (pattern, 0);
3068 if (!NILP (face))
3069 CHECK_SYMBOL (face, 1);
3070
3071 f = check_x_frame (frame);
3072
3073 /* Determine the width standard for comparison with the fonts we find. */
3074
3075 if (NILP (face))
3076 size_ref = 0;
3077 else
3078 {
3079 int face_id;
3080
3081 /* Don't die if we get called with a terminal frame. */
3082 if (! FRAME_X_P (f))
3083 error ("non-X frame used in `x-list-fonts'");
3084
3085 face_id = face_name_id_number (f, face);
3086
3087 if (face_id < 0 || face_id >= FRAME_N_PARAM_FACES (f)
3088 || FRAME_PARAM_FACES (f) [face_id] == 0)
3089 size_ref = f->display.x->font;
3090 else
3091 {
3092 size_ref = FRAME_PARAM_FACES (f) [face_id]->font;
3093 if (size_ref == (XFontStruct *) (~0))
3094 size_ref = f->display.x->font;
3095 }
3096 }
3097
3098 /* See if we cached the result for this particular query. */
3099 list = Fassoc (pattern,
3100 XCONS (FRAME_X_DISPLAY_INFO (f)->name_list_element)->cdr);
3101
3102 /* We have info in the cache for this PATTERN. */
3103 if (!NILP (list))
3104 {
3105 Lisp_Object tem, newlist;
3106
3107 /* We have info about this pattern. */
3108 list = XCONS (list)->cdr;
3109
3110 if (size_ref == 0)
3111 return list;
3112
3113 BLOCK_INPUT;
3114
3115 /* Filter the cached info and return just the fonts that match FACE. */
3116 newlist = Qnil;
3117 for (tem = list; CONSP (tem); tem = XCONS (tem)->cdr)
3118 {
3119 XFontStruct *thisinfo;
3120
3121 thisinfo = XLoadQueryFont (FRAME_X_DISPLAY (f),
3122 XSTRING (XCONS (tem)->car)->data);
3123
3124 if (thisinfo && same_size_fonts (thisinfo, size_ref))
3125 newlist = Fcons (XCONS (tem)->car, newlist);
3126
3127 XFreeFont (FRAME_X_DISPLAY (f), thisinfo);
3128 }
3129
3130 UNBLOCK_INPUT;
3131
3132 return newlist;
3133 }
3134
3135 BLOCK_INPUT;
3136
3137 /* Solaris 2.3 has a bug in XListFontsWithInfo. */
3138 #ifndef BROKEN_XLISTFONTSWITHINFO
3139 if (size_ref)
3140 names = XListFontsWithInfo (FRAME_X_DISPLAY (f),
3141 XSTRING (pattern)->data,
3142 2000, /* maxnames */
3143 &num_fonts, /* count_return */
3144 &info); /* info_return */
3145 else
3146 #endif
3147 names = XListFonts (FRAME_X_DISPLAY (f),
3148 XSTRING (pattern)->data,
3149 2000, /* maxnames */
3150 &num_fonts); /* count_return */
3151
3152 UNBLOCK_INPUT;
3153
3154 list = Qnil;
3155
3156 if (names)
3157 {
3158 int i;
3159 Lisp_Object full_list;
3160
3161 /* Make a list of all the fonts we got back.
3162 Store that in the font cache for the display. */
3163 full_list = Qnil;
3164 for (i = 0; i < num_fonts; i++)
3165 full_list = Fcons (build_string (names[i]), full_list);
3166 XCONS (FRAME_X_DISPLAY_INFO (f)->name_list_element)->cdr
3167 = Fcons (Fcons (pattern, full_list),
3168 XCONS (FRAME_X_DISPLAY_INFO (f)->name_list_element)->cdr);
3169
3170 /* Make a list of the fonts that have the right width. */
3171 list = Qnil;
3172 for (i = 0; i < num_fonts; i++)
3173 {
3174 int keeper;
3175
3176 if (!size_ref)
3177 keeper = 1;
3178 else
3179 {
3180 #ifdef BROKEN_XLISTFONTSWITHINFO
3181 XFontStruct *thisinfo;
3182
3183 BLOCK_INPUT;
3184 thisinfo = XLoadQueryFont (FRAME_X_DISPLAY (f), names[i]);
3185 UNBLOCK_INPUT;
3186
3187 keeper = thisinfo && same_size_fonts (thisinfo, size_ref);
3188 #else
3189 keeper = same_size_fonts (&info[i], size_ref);
3190 #endif
3191 }
3192 if (keeper)
3193 list = Fcons (build_string (names[i]), list);
3194 }
3195 list = Fnreverse (list);
3196
3197 BLOCK_INPUT;
3198 #ifndef BROKEN_XLISTFONTSWITHINFO
3199 if (size_ref)
3200 XFreeFontInfo (names, info, num_fonts);
3201 else
3202 #endif
3203 XFreeFontNames (names);
3204 UNBLOCK_INPUT;
3205 }
3206
3207 return list;
3208 }
3209
3210 \f
3211 DEFUN ("x-color-defined-p", Fx_color_defined_p, Sx_color_defined_p, 1, 2, 0,
3212 "Return non-nil if color COLOR is supported on frame FRAME.\n\
3213 If FRAME is omitted or nil, use the selected frame.")
3214 (color, frame)
3215 Lisp_Object color, frame;
3216 {
3217 XColor foo;
3218 FRAME_PTR f = check_x_frame (frame);
3219
3220 CHECK_STRING (color, 1);
3221
3222 if (defined_color (f, XSTRING (color)->data, &foo, 0))
3223 return Qt;
3224 else
3225 return Qnil;
3226 }
3227
3228 DEFUN ("x-color-values", Fx_color_values, Sx_color_values, 1, 2, 0,
3229 "Return a description of the color named COLOR on frame FRAME.\n\
3230 The value is a list of integer RGB values--(RED GREEN BLUE).\n\
3231 These values appear to range from 0 to 65280 or 65535, depending\n\
3232 on the system; white is (65280 65280 65280) or (65535 65535 65535).\n\
3233 If FRAME is omitted or nil, use the selected frame.")
3234 (color, frame)
3235 Lisp_Object color, frame;
3236 {
3237 XColor foo;
3238 FRAME_PTR f = check_x_frame (frame);
3239
3240 CHECK_STRING (color, 1);
3241
3242 if (defined_color (f, XSTRING (color)->data, &foo, 0))
3243 {
3244 Lisp_Object rgb[3];
3245
3246 rgb[0] = make_number (foo.red);
3247 rgb[1] = make_number (foo.green);
3248 rgb[2] = make_number (foo.blue);
3249 return Flist (3, rgb);
3250 }
3251 else
3252 return Qnil;
3253 }
3254
3255 DEFUN ("x-display-color-p", Fx_display_color_p, Sx_display_color_p, 0, 1, 0,
3256 "Return t if the X display supports color.\n\
3257 The optional argument DISPLAY specifies which display to ask about.\n\
3258 DISPLAY should be either a frame or a display name (a string).\n\
3259 If omitted or nil, that stands for the selected frame's display.")
3260 (display)
3261 Lisp_Object display;
3262 {
3263 struct x_display_info *dpyinfo = check_x_display_info (display);
3264
3265 if (dpyinfo->n_planes <= 2)
3266 return Qnil;
3267
3268 switch (dpyinfo->visual->class)
3269 {
3270 case StaticColor:
3271 case PseudoColor:
3272 case TrueColor:
3273 case DirectColor:
3274 return Qt;
3275
3276 default:
3277 return Qnil;
3278 }
3279 }
3280
3281 DEFUN ("x-display-grayscale-p", Fx_display_grayscale_p, Sx_display_grayscale_p,
3282 0, 1, 0,
3283 "Return t if the X display supports shades of gray.\n\
3284 The optional argument DISPLAY specifies which display to ask about.\n\
3285 DISPLAY should be either a frame or a display name (a string).\n\
3286 If omitted or nil, that stands for the selected frame's display.")
3287 (display)
3288 Lisp_Object display;
3289 {
3290 struct x_display_info *dpyinfo = check_x_display_info (display);
3291
3292 if (dpyinfo->n_planes <= 2)
3293 return Qnil;
3294
3295 return (dpyinfo->n_planes > 1
3296 && (dpyinfo->visual->class == StaticGray
3297 || dpyinfo->visual->class == GrayScale));
3298 }
3299
3300 DEFUN ("x-display-pixel-width", Fx_display_pixel_width, Sx_display_pixel_width,
3301 0, 1, 0,
3302 "Returns the width in pixels of the X display DISPLAY.\n\
3303 The optional argument DISPLAY specifies which display to ask about.\n\
3304 DISPLAY should be either a frame or a display name (a string).\n\
3305 If omitted or nil, that stands for the selected frame's display.")
3306 (display)
3307 Lisp_Object display;
3308 {
3309 struct x_display_info *dpyinfo = check_x_display_info (display);
3310
3311 return make_number (dpyinfo->width);
3312 }
3313
3314 DEFUN ("x-display-pixel-height", Fx_display_pixel_height,
3315 Sx_display_pixel_height, 0, 1, 0,
3316 "Returns the height in pixels of the X display DISPLAY.\n\
3317 The optional argument DISPLAY specifies which display to ask about.\n\
3318 DISPLAY should be either a frame or a display name (a string).\n\
3319 If omitted or nil, that stands for the selected frame's display.")
3320 (display)
3321 Lisp_Object display;
3322 {
3323 struct x_display_info *dpyinfo = check_x_display_info (display);
3324
3325 return make_number (dpyinfo->height);
3326 }
3327
3328 DEFUN ("x-display-planes", Fx_display_planes, Sx_display_planes,
3329 0, 1, 0,
3330 "Returns the number of bitplanes of the X display DISPLAY.\n\
3331 The optional argument DISPLAY specifies which display to ask about.\n\
3332 DISPLAY should be either a frame or a display name (a string).\n\
3333 If omitted or nil, that stands for the selected frame's display.")
3334 (display)
3335 Lisp_Object display;
3336 {
3337 struct x_display_info *dpyinfo = check_x_display_info (display);
3338
3339 return make_number (dpyinfo->n_planes);
3340 }
3341
3342 DEFUN ("x-display-color-cells", Fx_display_color_cells, Sx_display_color_cells,
3343 0, 1, 0,
3344 "Returns the number of color cells of the X display DISPLAY.\n\
3345 The optional argument DISPLAY specifies which display to ask about.\n\
3346 DISPLAY should be either a frame or a display name (a string).\n\
3347 If omitted or nil, that stands for the selected frame's display.")
3348 (display)
3349 Lisp_Object display;
3350 {
3351 struct x_display_info *dpyinfo = check_x_display_info (display);
3352
3353 return make_number (DisplayCells (dpyinfo->display,
3354 XScreenNumberOfScreen (dpyinfo->screen)));
3355 }
3356
3357 DEFUN ("x-server-max-request-size", Fx_server_max_request_size,
3358 Sx_server_max_request_size,
3359 0, 1, 0,
3360 "Returns the maximum request size of the X server of display DISPLAY.\n\
3361 The optional argument DISPLAY specifies which display to ask about.\n\
3362 DISPLAY should be either a frame or a display name (a string).\n\
3363 If omitted or nil, that stands for the selected frame's display.")
3364 (display)
3365 Lisp_Object display;
3366 {
3367 struct x_display_info *dpyinfo = check_x_display_info (display);
3368
3369 return make_number (MAXREQUEST (dpyinfo->display));
3370 }
3371
3372 DEFUN ("x-server-vendor", Fx_server_vendor, Sx_server_vendor, 0, 1, 0,
3373 "Returns the vendor ID string of the X server of display DISPLAY.\n\
3374 The optional argument DISPLAY specifies which display to ask about.\n\
3375 DISPLAY should be either a frame or a display name (a string).\n\
3376 If omitted or nil, that stands for the selected frame's display.")
3377 (display)
3378 Lisp_Object display;
3379 {
3380 struct x_display_info *dpyinfo = check_x_display_info (display);
3381 char *vendor = ServerVendor (dpyinfo->display);
3382
3383 if (! vendor) vendor = "";
3384 return build_string (vendor);
3385 }
3386
3387 DEFUN ("x-server-version", Fx_server_version, Sx_server_version, 0, 1, 0,
3388 "Returns the version numbers of the X server of display DISPLAY.\n\
3389 The value is a list of three integers: the major and minor\n\
3390 version numbers of the X Protocol in use, and the vendor-specific release\n\
3391 number. See also the function `x-server-vendor'.\n\n\
3392 The optional argument DISPLAY specifies which display to ask about.\n\
3393 DISPLAY should be either a frame or a display name (a string).\n\
3394 If omitted or nil, that stands for the selected frame's display.")
3395 (display)
3396 Lisp_Object display;
3397 {
3398 struct x_display_info *dpyinfo = check_x_display_info (display);
3399 Display *dpy = dpyinfo->display;
3400
3401 return Fcons (make_number (ProtocolVersion (dpy)),
3402 Fcons (make_number (ProtocolRevision (dpy)),
3403 Fcons (make_number (VendorRelease (dpy)), Qnil)));
3404 }
3405
3406 DEFUN ("x-display-screens", Fx_display_screens, Sx_display_screens, 0, 1, 0,
3407 "Returns the number of screens on the X server of display DISPLAY.\n\
3408 The optional argument DISPLAY specifies which display to ask about.\n\
3409 DISPLAY should be either a frame or a display name (a string).\n\
3410 If omitted or nil, that stands for the selected frame's display.")
3411 (display)
3412 Lisp_Object display;
3413 {
3414 struct x_display_info *dpyinfo = check_x_display_info (display);
3415
3416 return make_number (ScreenCount (dpyinfo->display));
3417 }
3418
3419 DEFUN ("x-display-mm-height", Fx_display_mm_height, Sx_display_mm_height, 0, 1, 0,
3420 "Returns the height in millimeters of the X display DISPLAY.\n\
3421 The optional argument DISPLAY specifies which display to ask about.\n\
3422 DISPLAY should be either a frame or a display name (a string).\n\
3423 If omitted or nil, that stands for the selected frame's display.")
3424 (display)
3425 Lisp_Object display;
3426 {
3427 struct x_display_info *dpyinfo = check_x_display_info (display);
3428
3429 return make_number (HeightMMOfScreen (dpyinfo->screen));
3430 }
3431
3432 DEFUN ("x-display-mm-width", Fx_display_mm_width, Sx_display_mm_width, 0, 1, 0,
3433 "Returns the width in millimeters of the X display DISPLAY.\n\
3434 The optional argument DISPLAY specifies which display to ask about.\n\
3435 DISPLAY should be either a frame or a display name (a string).\n\
3436 If omitted or nil, that stands for the selected frame's display.")
3437 (display)
3438 Lisp_Object display;
3439 {
3440 struct x_display_info *dpyinfo = check_x_display_info (display);
3441
3442 return make_number (WidthMMOfScreen (dpyinfo->screen));
3443 }
3444
3445 DEFUN ("x-display-backing-store", Fx_display_backing_store,
3446 Sx_display_backing_store, 0, 1, 0,
3447 "Returns an indication of whether X display DISPLAY does backing store.\n\
3448 The value may be `always', `when-mapped', or `not-useful'.\n\
3449 The optional argument DISPLAY specifies which display to ask about.\n\
3450 DISPLAY should be either a frame or a display name (a string).\n\
3451 If omitted or nil, that stands for the selected frame's display.")
3452 (display)
3453 Lisp_Object display;
3454 {
3455 struct x_display_info *dpyinfo = check_x_display_info (display);
3456
3457 switch (DoesBackingStore (dpyinfo->screen))
3458 {
3459 case Always:
3460 return intern ("always");
3461
3462 case WhenMapped:
3463 return intern ("when-mapped");
3464
3465 case NotUseful:
3466 return intern ("not-useful");
3467
3468 default:
3469 error ("Strange value for BackingStore parameter of screen");
3470 }
3471 }
3472
3473 DEFUN ("x-display-visual-class", Fx_display_visual_class,
3474 Sx_display_visual_class, 0, 1, 0,
3475 "Returns the visual class of the X display DISPLAY.\n\
3476 The value is one of the symbols `static-gray', `gray-scale',\n\
3477 `static-color', `pseudo-color', `true-color', or `direct-color'.\n\n\
3478 The optional argument DISPLAY specifies which display to ask about.\n\
3479 DISPLAY should be either a frame or a display name (a string).\n\
3480 If omitted or nil, that stands for the selected frame's display.")
3481 (display)
3482 Lisp_Object display;
3483 {
3484 struct x_display_info *dpyinfo = check_x_display_info (display);
3485
3486 switch (dpyinfo->visual->class)
3487 {
3488 case StaticGray: return (intern ("static-gray"));
3489 case GrayScale: return (intern ("gray-scale"));
3490 case StaticColor: return (intern ("static-color"));
3491 case PseudoColor: return (intern ("pseudo-color"));
3492 case TrueColor: return (intern ("true-color"));
3493 case DirectColor: return (intern ("direct-color"));
3494 default:
3495 error ("Display has an unknown visual class");
3496 }
3497 }
3498
3499 DEFUN ("x-display-save-under", Fx_display_save_under,
3500 Sx_display_save_under, 0, 1, 0,
3501 "Returns t if the X display DISPLAY supports the save-under feature.\n\
3502 The optional argument DISPLAY specifies which display to ask about.\n\
3503 DISPLAY should be either a frame or a display name (a string).\n\
3504 If omitted or nil, that stands for the selected frame's display.")
3505 (display)
3506 Lisp_Object display;
3507 {
3508 struct x_display_info *dpyinfo = check_x_display_info (display);
3509
3510 if (DoesSaveUnders (dpyinfo->screen) == True)
3511 return Qt;
3512 else
3513 return Qnil;
3514 }
3515 \f
3516 int
3517 x_pixel_width (f)
3518 register struct frame *f;
3519 {
3520 return PIXEL_WIDTH (f);
3521 }
3522
3523 int
3524 x_pixel_height (f)
3525 register struct frame *f;
3526 {
3527 return PIXEL_HEIGHT (f);
3528 }
3529
3530 int
3531 x_char_width (f)
3532 register struct frame *f;
3533 {
3534 return FONT_WIDTH (f->display.x->font);
3535 }
3536
3537 int
3538 x_char_height (f)
3539 register struct frame *f;
3540 {
3541 return f->display.x->line_height;
3542 }
3543
3544 int
3545 x_screen_planes (frame)
3546 Lisp_Object frame;
3547 {
3548 return FRAME_X_DISPLAY_INFO (XFRAME (frame))->n_planes;
3549 }
3550 \f
3551 #if 0 /* These no longer seem like the right way to do things. */
3552
3553 /* Draw a rectangle on the frame with left top corner including
3554 the character specified by LEFT_CHAR and TOP_CHAR. The rectangle is
3555 CHARS by LINES wide and long and is the color of the cursor. */
3556
3557 void
3558 x_rectangle (f, gc, left_char, top_char, chars, lines)
3559 register struct frame *f;
3560 GC gc;
3561 register int top_char, left_char, chars, lines;
3562 {
3563 int width;
3564 int height;
3565 int left = (left_char * FONT_WIDTH (f->display.x->font)
3566 + f->display.x->internal_border_width);
3567 int top = (top_char * f->display.x->line_height
3568 + f->display.x->internal_border_width);
3569
3570 if (chars < 0)
3571 width = FONT_WIDTH (f->display.x->font) / 2;
3572 else
3573 width = FONT_WIDTH (f->display.x->font) * chars;
3574 if (lines < 0)
3575 height = f->display.x->line_height / 2;
3576 else
3577 height = f->display.x->line_height * lines;
3578
3579 XDrawRectangle (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
3580 gc, left, top, width, height);
3581 }
3582
3583 DEFUN ("x-draw-rectangle", Fx_draw_rectangle, Sx_draw_rectangle, 5, 5, 0,
3584 "Draw a rectangle on FRAME between coordinates specified by\n\
3585 numbers X0, Y0, X1, Y1 in the cursor pixel.")
3586 (frame, X0, Y0, X1, Y1)
3587 register Lisp_Object frame, X0, X1, Y0, Y1;
3588 {
3589 register int x0, y0, x1, y1, top, left, n_chars, n_lines;
3590
3591 CHECK_LIVE_FRAME (frame, 0);
3592 CHECK_NUMBER (X0, 0);
3593 CHECK_NUMBER (Y0, 1);
3594 CHECK_NUMBER (X1, 2);
3595 CHECK_NUMBER (Y1, 3);
3596
3597 x0 = XINT (X0);
3598 x1 = XINT (X1);
3599 y0 = XINT (Y0);
3600 y1 = XINT (Y1);
3601
3602 if (y1 > y0)
3603 {
3604 top = y0;
3605 n_lines = y1 - y0 + 1;
3606 }
3607 else
3608 {
3609 top = y1;
3610 n_lines = y0 - y1 + 1;
3611 }
3612
3613 if (x1 > x0)
3614 {
3615 left = x0;
3616 n_chars = x1 - x0 + 1;
3617 }
3618 else
3619 {
3620 left = x1;
3621 n_chars = x0 - x1 + 1;
3622 }
3623
3624 BLOCK_INPUT;
3625 x_rectangle (XFRAME (frame), XFRAME (frame)->display.x->cursor_gc,
3626 left, top, n_chars, n_lines);
3627 UNBLOCK_INPUT;
3628
3629 return Qt;
3630 }
3631
3632 DEFUN ("x-erase-rectangle", Fx_erase_rectangle, Sx_erase_rectangle, 5, 5, 0,
3633 "Draw a rectangle drawn on FRAME between coordinates\n\
3634 X0, Y0, X1, Y1 in the regular background-pixel.")
3635 (frame, X0, Y0, X1, Y1)
3636 register Lisp_Object frame, X0, Y0, X1, Y1;
3637 {
3638 register int x0, y0, x1, y1, top, left, n_chars, n_lines;
3639
3640 CHECK_LIVE_FRAME (frame, 0);
3641 CHECK_NUMBER (X0, 0);
3642 CHECK_NUMBER (Y0, 1);
3643 CHECK_NUMBER (X1, 2);
3644 CHECK_NUMBER (Y1, 3);
3645
3646 x0 = XINT (X0);
3647 x1 = XINT (X1);
3648 y0 = XINT (Y0);
3649 y1 = XINT (Y1);
3650
3651 if (y1 > y0)
3652 {
3653 top = y0;
3654 n_lines = y1 - y0 + 1;
3655 }
3656 else
3657 {
3658 top = y1;
3659 n_lines = y0 - y1 + 1;
3660 }
3661
3662 if (x1 > x0)
3663 {
3664 left = x0;
3665 n_chars = x1 - x0 + 1;
3666 }
3667 else
3668 {
3669 left = x1;
3670 n_chars = x0 - x1 + 1;
3671 }
3672
3673 BLOCK_INPUT;
3674 x_rectangle (XFRAME (frame), XFRAME (frame)->display.x->reverse_gc,
3675 left, top, n_chars, n_lines);
3676 UNBLOCK_INPUT;
3677
3678 return Qt;
3679 }
3680
3681 /* Draw lines around the text region beginning at the character position
3682 TOP_X, TOP_Y and ending at BOTTOM_X and BOTTOM_Y. GC specifies the
3683 pixel and line characteristics. */
3684
3685 #define line_len(line) (FRAME_CURRENT_GLYPHS (f)->used[(line)])
3686
3687 static void
3688 outline_region (f, gc, top_x, top_y, bottom_x, bottom_y)
3689 register struct frame *f;
3690 GC gc;
3691 int top_x, top_y, bottom_x, bottom_y;
3692 {
3693 register int ibw = f->display.x->internal_border_width;
3694 register int font_w = FONT_WIDTH (f->display.x->font);
3695 register int font_h = f->display.x->line_height;
3696 int y = top_y;
3697 int x = line_len (y);
3698 XPoint *pixel_points
3699 = (XPoint *) alloca (((bottom_y - top_y + 2) * 4) * sizeof (XPoint));
3700 register XPoint *this_point = pixel_points;
3701
3702 /* Do the horizontal top line/lines */
3703 if (top_x == 0)
3704 {
3705 this_point->x = ibw;
3706 this_point->y = ibw + (font_h * top_y);
3707 this_point++;
3708 if (x == 0)
3709 this_point->x = ibw + (font_w / 2); /* Half-size for newline chars. */
3710 else
3711 this_point->x = ibw + (font_w * x);
3712 this_point->y = (this_point - 1)->y;
3713 }
3714 else
3715 {
3716 this_point->x = ibw;
3717 this_point->y = ibw + (font_h * (top_y + 1));
3718 this_point++;
3719 this_point->x = ibw + (font_w * top_x);
3720 this_point->y = (this_point - 1)->y;
3721 this_point++;
3722 this_point->x = (this_point - 1)->x;
3723 this_point->y = ibw + (font_h * top_y);
3724 this_point++;
3725 this_point->x = ibw + (font_w * x);
3726 this_point->y = (this_point - 1)->y;
3727 }
3728
3729 /* Now do the right side. */
3730 while (y < bottom_y)
3731 { /* Right vertical edge */
3732 this_point++;
3733 this_point->x = (this_point - 1)->x;
3734 this_point->y = ibw + (font_h * (y + 1));
3735 this_point++;
3736
3737 y++; /* Horizontal connection to next line */
3738 x = line_len (y);
3739 if (x == 0)
3740 this_point->x = ibw + (font_w / 2);
3741 else
3742 this_point->x = ibw + (font_w * x);
3743
3744 this_point->y = (this_point - 1)->y;
3745 }
3746
3747 /* Now do the bottom and connect to the top left point. */
3748 this_point->x = ibw + (font_w * (bottom_x + 1));
3749
3750 this_point++;
3751 this_point->x = (this_point - 1)->x;
3752 this_point->y = ibw + (font_h * (bottom_y + 1));
3753 this_point++;
3754 this_point->x = ibw;
3755 this_point->y = (this_point - 1)->y;
3756 this_point++;
3757 this_point->x = pixel_points->x;
3758 this_point->y = pixel_points->y;
3759
3760 XDrawLines (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
3761 gc, pixel_points,
3762 (this_point - pixel_points + 1), CoordModeOrigin);
3763 }
3764
3765 DEFUN ("x-contour-region", Fx_contour_region, Sx_contour_region, 1, 1, 0,
3766 "Highlight the region between point and the character under the mouse\n\
3767 selected frame.")
3768 (event)
3769 register Lisp_Object event;
3770 {
3771 register int x0, y0, x1, y1;
3772 register struct frame *f = selected_frame;
3773 register int p1, p2;
3774
3775 CHECK_CONS (event, 0);
3776
3777 BLOCK_INPUT;
3778 x0 = XINT (Fcar (Fcar (event)));
3779 y0 = XINT (Fcar (Fcdr (Fcar (event))));
3780
3781 /* If the mouse is past the end of the line, don't that area. */
3782 /* ReWrite this... */
3783
3784 x1 = f->cursor_x;
3785 y1 = f->cursor_y;
3786
3787 if (y1 > y0) /* point below mouse */
3788 outline_region (f, f->display.x->cursor_gc,
3789 x0, y0, x1, y1);
3790 else if (y1 < y0) /* point above mouse */
3791 outline_region (f, f->display.x->cursor_gc,
3792 x1, y1, x0, y0);
3793 else /* same line: draw horizontal rectangle */
3794 {
3795 if (x1 > x0)
3796 x_rectangle (f, f->display.x->cursor_gc,
3797 x0, y0, (x1 - x0 + 1), 1);
3798 else if (x1 < x0)
3799 x_rectangle (f, f->display.x->cursor_gc,
3800 x1, y1, (x0 - x1 + 1), 1);
3801 }
3802
3803 XFlush (FRAME_X_DISPLAY (f));
3804 UNBLOCK_INPUT;
3805
3806 return Qnil;
3807 }
3808
3809 DEFUN ("x-uncontour-region", Fx_uncontour_region, Sx_uncontour_region, 1, 1, 0,
3810 "Erase any highlighting of the region between point and the character\n\
3811 at X, Y on the selected frame.")
3812 (event)
3813 register Lisp_Object event;
3814 {
3815 register int x0, y0, x1, y1;
3816 register struct frame *f = selected_frame;
3817
3818 BLOCK_INPUT;
3819 x0 = XINT (Fcar (Fcar (event)));
3820 y0 = XINT (Fcar (Fcdr (Fcar (event))));
3821 x1 = f->cursor_x;
3822 y1 = f->cursor_y;
3823
3824 if (y1 > y0) /* point below mouse */
3825 outline_region (f, f->display.x->reverse_gc,
3826 x0, y0, x1, y1);
3827 else if (y1 < y0) /* point above mouse */
3828 outline_region (f, f->display.x->reverse_gc,
3829 x1, y1, x0, y0);
3830 else /* same line: draw horizontal rectangle */
3831 {
3832 if (x1 > x0)
3833 x_rectangle (f, f->display.x->reverse_gc,
3834 x0, y0, (x1 - x0 + 1), 1);
3835 else if (x1 < x0)
3836 x_rectangle (f, f->display.x->reverse_gc,
3837 x1, y1, (x0 - x1 + 1), 1);
3838 }
3839 UNBLOCK_INPUT;
3840
3841 return Qnil;
3842 }
3843
3844 #if 0
3845 int contour_begin_x, contour_begin_y;
3846 int contour_end_x, contour_end_y;
3847 int contour_npoints;
3848
3849 /* Clip the top part of the contour lines down (and including) line Y_POS.
3850 If X_POS is in the middle (rather than at the end) of the line, drop
3851 down a line at that character. */
3852
3853 static void
3854 clip_contour_top (y_pos, x_pos)
3855 {
3856 register XPoint *begin = contour_lines[y_pos].top_left;
3857 register XPoint *end;
3858 register int npoints;
3859 register struct display_line *line = selected_frame->phys_lines[y_pos + 1];
3860
3861 if (x_pos >= line->len - 1) /* Draw one, straight horizontal line. */
3862 {
3863 end = contour_lines[y_pos].top_right;
3864 npoints = (end - begin + 1);
3865 XDrawLines (x_current_display, contour_window,
3866 contour_erase_gc, begin_erase, npoints, CoordModeOrigin);
3867
3868 bcopy (end, begin + 1, contour_last_point - end + 1);
3869 contour_last_point -= (npoints - 2);
3870 XDrawLines (x_current_display, contour_window,
3871 contour_erase_gc, begin, 2, CoordModeOrigin);
3872 XFlush (x_current_display);
3873
3874 /* Now, update contour_lines structure. */
3875 }
3876 /* ______. */
3877 else /* |________*/
3878 {
3879 register XPoint *p = begin + 1;
3880 end = contour_lines[y_pos].bottom_right;
3881 npoints = (end - begin + 1);
3882 XDrawLines (x_current_display, contour_window,
3883 contour_erase_gc, begin_erase, npoints, CoordModeOrigin);
3884
3885 p->y = begin->y;
3886 p->x = ibw + (font_w * (x_pos + 1));
3887 p++;
3888 p->y = begin->y + font_h;
3889 p->x = (p - 1)->x;
3890 bcopy (end, begin + 3, contour_last_point - end + 1);
3891 contour_last_point -= (npoints - 5);
3892 XDrawLines (x_current_display, contour_window,
3893 contour_erase_gc, begin, 4, CoordModeOrigin);
3894 XFlush (x_current_display);
3895
3896 /* Now, update contour_lines structure. */
3897 }
3898 }
3899
3900 /* Erase the top horizontal lines of the contour, and then extend
3901 the contour upwards. */
3902
3903 static void
3904 extend_contour_top (line)
3905 {
3906 }
3907
3908 static void
3909 clip_contour_bottom (x_pos, y_pos)
3910 int x_pos, y_pos;
3911 {
3912 }
3913
3914 static void
3915 extend_contour_bottom (x_pos, y_pos)
3916 {
3917 }
3918
3919 DEFUN ("x-select-region", Fx_select_region, Sx_select_region, 1, 1, "e",
3920 "")
3921 (event)
3922 Lisp_Object event;
3923 {
3924 register struct frame *f = selected_frame;
3925 register int point_x = f->cursor_x;
3926 register int point_y = f->cursor_y;
3927 register int mouse_below_point;
3928 register Lisp_Object obj;
3929 register int x_contour_x, x_contour_y;
3930
3931 x_contour_x = x_mouse_x;
3932 x_contour_y = x_mouse_y;
3933 if (x_contour_y > point_y || (x_contour_y == point_y
3934 && x_contour_x > point_x))
3935 {
3936 mouse_below_point = 1;
3937 outline_region (f, f->display.x->cursor_gc, point_x, point_y,
3938 x_contour_x, x_contour_y);
3939 }
3940 else
3941 {
3942 mouse_below_point = 0;
3943 outline_region (f, f->display.x->cursor_gc, x_contour_x, x_contour_y,
3944 point_x, point_y);
3945 }
3946
3947 while (1)
3948 {
3949 obj = read_char (-1, 0, 0, Qnil, 0);
3950 if (!CONSP (obj))
3951 break;
3952
3953 if (mouse_below_point)
3954 {
3955 if (x_mouse_y <= point_y) /* Flipped. */
3956 {
3957 mouse_below_point = 0;
3958
3959 outline_region (f, f->display.x->reverse_gc, point_x, point_y,
3960 x_contour_x, x_contour_y);
3961 outline_region (f, f->display.x->cursor_gc, x_mouse_x, x_mouse_y,
3962 point_x, point_y);
3963 }
3964 else if (x_mouse_y < x_contour_y) /* Bottom clipped. */
3965 {
3966 clip_contour_bottom (x_mouse_y);
3967 }
3968 else if (x_mouse_y > x_contour_y) /* Bottom extended. */
3969 {
3970 extend_bottom_contour (x_mouse_y);
3971 }
3972
3973 x_contour_x = x_mouse_x;
3974 x_contour_y = x_mouse_y;
3975 }
3976 else /* mouse above or same line as point */
3977 {
3978 if (x_mouse_y >= point_y) /* Flipped. */
3979 {
3980 mouse_below_point = 1;
3981
3982 outline_region (f, f->display.x->reverse_gc,
3983 x_contour_x, x_contour_y, point_x, point_y);
3984 outline_region (f, f->display.x->cursor_gc, point_x, point_y,
3985 x_mouse_x, x_mouse_y);
3986 }
3987 else if (x_mouse_y > x_contour_y) /* Top clipped. */
3988 {
3989 clip_contour_top (x_mouse_y);
3990 }
3991 else if (x_mouse_y < x_contour_y) /* Top extended. */
3992 {
3993 extend_contour_top (x_mouse_y);
3994 }
3995 }
3996 }
3997
3998 unread_command_event = obj;
3999 if (mouse_below_point)
4000 {
4001 contour_begin_x = point_x;
4002 contour_begin_y = point_y;
4003 contour_end_x = x_contour_x;
4004 contour_end_y = x_contour_y;
4005 }
4006 else
4007 {
4008 contour_begin_x = x_contour_x;
4009 contour_begin_y = x_contour_y;
4010 contour_end_x = point_x;
4011 contour_end_y = point_y;
4012 }
4013 }
4014 #endif
4015
4016 DEFUN ("x-horizontal-line", Fx_horizontal_line, Sx_horizontal_line, 1, 1, "e",
4017 "")
4018 (event)
4019 Lisp_Object event;
4020 {
4021 register Lisp_Object obj;
4022 struct frame *f = selected_frame;
4023 register struct window *w = XWINDOW (selected_window);
4024 register GC line_gc = f->display.x->cursor_gc;
4025 register GC erase_gc = f->display.x->reverse_gc;
4026 #if 0
4027 char dash_list[] = {6, 4, 6, 4};
4028 int dashes = 4;
4029 XGCValues gc_values;
4030 #endif
4031 register int previous_y;
4032 register int line = (x_mouse_y + 1) * f->display.x->line_height
4033 + f->display.x->internal_border_width;
4034 register int left = f->display.x->internal_border_width
4035 + (w->left
4036 * FONT_WIDTH (f->display.x->font));
4037 register int right = left + (w->width
4038 * FONT_WIDTH (f->display.x->font))
4039 - f->display.x->internal_border_width;
4040
4041 #if 0
4042 BLOCK_INPUT;
4043 gc_values.foreground = f->display.x->cursor_pixel;
4044 gc_values.background = f->display.x->background_pixel;
4045 gc_values.line_width = 1;
4046 gc_values.line_style = LineOnOffDash;
4047 gc_values.cap_style = CapRound;
4048 gc_values.join_style = JoinRound;
4049
4050 line_gc = XCreateGC (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
4051 GCLineStyle | GCJoinStyle | GCCapStyle
4052 | GCLineWidth | GCForeground | GCBackground,
4053 &gc_values);
4054 XSetDashes (FRAME_X_DISPLAY (f), line_gc, 0, dash_list, dashes);
4055 gc_values.foreground = f->display.x->background_pixel;
4056 gc_values.background = f->display.x->foreground_pixel;
4057 erase_gc = XCreateGC (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
4058 GCLineStyle | GCJoinStyle | GCCapStyle
4059 | GCLineWidth | GCForeground | GCBackground,
4060 &gc_values);
4061 XSetDashes (FRAME_X_DISPLAY (f), erase_gc, 0, dash_list, dashes);
4062 #endif
4063
4064 while (1)
4065 {
4066 BLOCK_INPUT;
4067 if (x_mouse_y >= XINT (w->top)
4068 && x_mouse_y < XINT (w->top) + XINT (w->height) - 1)
4069 {
4070 previous_y = x_mouse_y;
4071 line = (x_mouse_y + 1) * f->display.x->line_height
4072 + f->display.x->internal_border_width;
4073 XDrawLine (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
4074 line_gc, left, line, right, line);
4075 }
4076 XFlush (FRAME_X_DISPLAY (f));
4077 UNBLOCK_INPUT;
4078
4079 do
4080 {
4081 obj = read_char (-1, 0, 0, Qnil, 0);
4082 if (!CONSP (obj)
4083 || (! EQ (Fcar (Fcdr (Fcdr (obj))),
4084 Qvertical_scroll_bar))
4085 || x_mouse_grabbed)
4086 {
4087 BLOCK_INPUT;
4088 XDrawLine (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
4089 erase_gc, left, line, right, line);
4090 UNBLOCK_INPUT;
4091 unread_command_event = obj;
4092 #if 0
4093 XFreeGC (FRAME_X_DISPLAY (f), line_gc);
4094 XFreeGC (FRAME_X_DISPLAY (f), erase_gc);
4095 #endif
4096 return Qnil;
4097 }
4098 }
4099 while (x_mouse_y == previous_y);
4100
4101 BLOCK_INPUT;
4102 XDrawLine (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
4103 erase_gc, left, line, right, line);
4104 UNBLOCK_INPUT;
4105 }
4106 }
4107 #endif
4108 \f
4109 #if 0
4110 /* These keep track of the rectangle following the pointer. */
4111 int mouse_track_top, mouse_track_left, mouse_track_width;
4112
4113 /* Offset in buffer of character under the pointer, or 0. */
4114 int mouse_buffer_offset;
4115
4116 DEFUN ("x-track-pointer", Fx_track_pointer, Sx_track_pointer, 0, 0, 0,
4117 "Track the pointer.")
4118 ()
4119 {
4120 static Cursor current_pointer_shape;
4121 FRAME_PTR f = x_mouse_frame;
4122
4123 BLOCK_INPUT;
4124 if (EQ (Vmouse_frame_part, Qtext_part)
4125 && (current_pointer_shape != f->display.x->nontext_cursor))
4126 {
4127 unsigned char c;
4128 struct buffer *buf;
4129
4130 current_pointer_shape = f->display.x->nontext_cursor;
4131 XDefineCursor (FRAME_X_DISPLAY (f),
4132 FRAME_X_WINDOW (f),
4133 current_pointer_shape);
4134
4135 buf = XBUFFER (XWINDOW (Vmouse_window)->buffer);
4136 c = *(BUF_CHAR_ADDRESS (buf, mouse_buffer_offset));
4137 }
4138 else if (EQ (Vmouse_frame_part, Qmodeline_part)
4139 && (current_pointer_shape != f->display.x->modeline_cursor))
4140 {
4141 current_pointer_shape = f->display.x->modeline_cursor;
4142 XDefineCursor (FRAME_X_DISPLAY (f),
4143 FRAME_X_WINDOW (f),
4144 current_pointer_shape);
4145 }
4146
4147 XFlush (FRAME_X_DISPLAY (f));
4148 UNBLOCK_INPUT;
4149 }
4150 #endif
4151
4152 #if 0
4153 DEFUN ("x-track-pointer", Fx_track_pointer, Sx_track_pointer, 1, 1, "e",
4154 "Draw rectangle around character under mouse pointer, if there is one.")
4155 (event)
4156 Lisp_Object event;
4157 {
4158 struct window *w = XWINDOW (Vmouse_window);
4159 struct frame *f = XFRAME (WINDOW_FRAME (w));
4160 struct buffer *b = XBUFFER (w->buffer);
4161 Lisp_Object obj;
4162
4163 if (! EQ (Vmouse_window, selected_window))
4164 return Qnil;
4165
4166 if (EQ (event, Qnil))
4167 {
4168 int x, y;
4169
4170 x_read_mouse_position (selected_frame, &x, &y);
4171 }
4172
4173 BLOCK_INPUT;
4174 mouse_track_width = 0;
4175 mouse_track_left = mouse_track_top = -1;
4176
4177 do
4178 {
4179 if ((x_mouse_x != mouse_track_left
4180 && (x_mouse_x < mouse_track_left
4181 || x_mouse_x > (mouse_track_left + mouse_track_width)))
4182 || x_mouse_y != mouse_track_top)
4183 {
4184 int hp = 0; /* Horizontal position */
4185 int len = FRAME_CURRENT_GLYPHS (f)->used[x_mouse_y];
4186 int p = FRAME_CURRENT_GLYPHS (f)->bufp[x_mouse_y];
4187 int tab_width = XINT (b->tab_width);
4188 int ctl_arrow_p = !NILP (b->ctl_arrow);
4189 unsigned char c;
4190 int mode_line_vpos = XFASTINT (w->height) + XFASTINT (w->top) - 1;
4191 int in_mode_line = 0;
4192
4193 if (! FRAME_CURRENT_GLYPHS (f)->enable[x_mouse_y])
4194 break;
4195
4196 /* Erase previous rectangle. */
4197 if (mouse_track_width)
4198 {
4199 x_rectangle (f, f->display.x->reverse_gc,
4200 mouse_track_left, mouse_track_top,
4201 mouse_track_width, 1);
4202
4203 if ((mouse_track_left == f->phys_cursor_x
4204 || mouse_track_left == f->phys_cursor_x - 1)
4205 && mouse_track_top == f->phys_cursor_y)
4206 {
4207 x_display_cursor (f, 1);
4208 }
4209 }
4210
4211 mouse_track_left = x_mouse_x;
4212 mouse_track_top = x_mouse_y;
4213 mouse_track_width = 0;
4214
4215 if (mouse_track_left > len) /* Past the end of line. */
4216 goto draw_or_not;
4217
4218 if (mouse_track_top == mode_line_vpos)
4219 {
4220 in_mode_line = 1;
4221 goto draw_or_not;
4222 }
4223
4224 if (tab_width <= 0 || tab_width > 20) tab_width = 8;
4225 do
4226 {
4227 c = FETCH_CHAR (p);
4228 if (len == f->width && hp == len - 1 && c != '\n')
4229 goto draw_or_not;
4230
4231 switch (c)
4232 {
4233 case '\t':
4234 mouse_track_width = tab_width - (hp % tab_width);
4235 p++;
4236 hp += mouse_track_width;
4237 if (hp > x_mouse_x)
4238 {
4239 mouse_track_left = hp - mouse_track_width;
4240 goto draw_or_not;
4241 }
4242 continue;
4243
4244 case '\n':
4245 mouse_track_width = -1;
4246 goto draw_or_not;
4247
4248 default:
4249 if (ctl_arrow_p && (c < 040 || c == 0177))
4250 {
4251 if (p > ZV)
4252 goto draw_or_not;
4253
4254 mouse_track_width = 2;
4255 p++;
4256 hp +=2;
4257 if (hp > x_mouse_x)
4258 {
4259 mouse_track_left = hp - mouse_track_width;
4260 goto draw_or_not;
4261 }
4262 }
4263 else
4264 {
4265 mouse_track_width = 1;
4266 p++;
4267 hp++;
4268 }
4269 continue;
4270 }
4271 }
4272 while (hp <= x_mouse_x);
4273
4274 draw_or_not:
4275 if (mouse_track_width) /* Over text; use text pointer shape. */
4276 {
4277 XDefineCursor (FRAME_X_DISPLAY (f),
4278 FRAME_X_WINDOW (f),
4279 f->display.x->text_cursor);
4280 x_rectangle (f, f->display.x->cursor_gc,
4281 mouse_track_left, mouse_track_top,
4282 mouse_track_width, 1);
4283 }
4284 else if (in_mode_line)
4285 XDefineCursor (FRAME_X_DISPLAY (f),
4286 FRAME_X_WINDOW (f),
4287 f->display.x->modeline_cursor);
4288 else
4289 XDefineCursor (FRAME_X_DISPLAY (f),
4290 FRAME_X_WINDOW (f),
4291 f->display.x->nontext_cursor);
4292 }
4293
4294 XFlush (FRAME_X_DISPLAY (f));
4295 UNBLOCK_INPUT;
4296
4297 obj = read_char (-1, 0, 0, Qnil, 0);
4298 BLOCK_INPUT;
4299 }
4300 while (CONSP (obj) /* Mouse event */
4301 && EQ (Fcar (Fcdr (Fcdr (obj))), Qnil) /* Not scroll bar */
4302 && EQ (Vmouse_depressed, Qnil) /* Only motion events */
4303 && EQ (Vmouse_window, selected_window) /* In this window */
4304 && x_mouse_frame);
4305
4306 unread_command_event = obj;
4307
4308 if (mouse_track_width)
4309 {
4310 x_rectangle (f, f->display.x->reverse_gc,
4311 mouse_track_left, mouse_track_top,
4312 mouse_track_width, 1);
4313 mouse_track_width = 0;
4314 if ((mouse_track_left == f->phys_cursor_x
4315 || mouse_track_left - 1 == f->phys_cursor_x)
4316 && mouse_track_top == f->phys_cursor_y)
4317 {
4318 x_display_cursor (f, 1);
4319 }
4320 }
4321 XDefineCursor (FRAME_X_DISPLAY (f),
4322 FRAME_X_WINDOW (f),
4323 f->display.x->nontext_cursor);
4324 XFlush (FRAME_X_DISPLAY (f));
4325 UNBLOCK_INPUT;
4326
4327 return Qnil;
4328 }
4329 #endif
4330 \f
4331 #if 0
4332 #include "glyphs.h"
4333
4334 /* Draw a pixmap specified by IMAGE_DATA of dimensions WIDTH and HEIGHT
4335 on the frame F at position X, Y. */
4336
4337 x_draw_pixmap (f, x, y, image_data, width, height)
4338 struct frame *f;
4339 int x, y, width, height;
4340 char *image_data;
4341 {
4342 Pixmap image;
4343
4344 image = XCreateBitmapFromData (FRAME_X_DISPLAY (f),
4345 FRAME_X_WINDOW (f), image_data,
4346 width, height);
4347 XCopyPlane (FRAME_X_DISPLAY (f), image, FRAME_X_WINDOW (f),
4348 f->display.x->normal_gc, 0, 0, width, height, x, y);
4349 }
4350 #endif
4351 \f
4352 #if 0 /* I'm told these functions are superfluous
4353 given the ability to bind function keys. */
4354
4355 #ifdef HAVE_X11
4356 DEFUN ("x-rebind-key", Fx_rebind_key, Sx_rebind_key, 3, 3, 0,
4357 "Rebind X keysym KEYSYM, with MODIFIERS, to generate NEWSTRING.\n\
4358 KEYSYM is a string which conforms to the X keysym definitions found\n\
4359 in X11/keysymdef.h, sans the initial XK_. MODIFIERS is nil or a\n\
4360 list of strings specifying modifier keys such as Control_L, which must\n\
4361 also be depressed for NEWSTRING to appear.")
4362 (x_keysym, modifiers, newstring)
4363 register Lisp_Object x_keysym;
4364 register Lisp_Object modifiers;
4365 register Lisp_Object newstring;
4366 {
4367 char *rawstring;
4368 register KeySym keysym;
4369 KeySym modifier_list[16];
4370
4371 check_x ();
4372 CHECK_STRING (x_keysym, 1);
4373 CHECK_STRING (newstring, 3);
4374
4375 keysym = XStringToKeysym ((char *) XSTRING (x_keysym)->data);
4376 if (keysym == NoSymbol)
4377 error ("Keysym does not exist");
4378
4379 if (NILP (modifiers))
4380 XRebindKeysym (x_current_display, keysym, modifier_list, 0,
4381 XSTRING (newstring)->data, XSTRING (newstring)->size);
4382 else
4383 {
4384 register Lisp_Object rest, mod;
4385 register int i = 0;
4386
4387 for (rest = modifiers; !NILP (rest); rest = Fcdr (rest))
4388 {
4389 if (i == 16)
4390 error ("Can't have more than 16 modifiers");
4391
4392 mod = Fcar (rest);
4393 CHECK_STRING (mod, 3);
4394 modifier_list[i] = XStringToKeysym ((char *) XSTRING (mod)->data);
4395 #ifndef HAVE_X11R5
4396 if (modifier_list[i] == NoSymbol
4397 || !(IsModifierKey (modifier_list[i])
4398 || ((unsigned)(modifier_list[i]) == XK_Mode_switch)
4399 || ((unsigned)(modifier_list[i]) == XK_Num_Lock)))
4400 #else
4401 if (modifier_list[i] == NoSymbol
4402 || !IsModifierKey (modifier_list[i]))
4403 #endif
4404 error ("Element is not a modifier keysym");
4405 i++;
4406 }
4407
4408 XRebindKeysym (x_current_display, keysym, modifier_list, i,
4409 XSTRING (newstring)->data, XSTRING (newstring)->size);
4410 }
4411
4412 return Qnil;
4413 }
4414
4415 DEFUN ("x-rebind-keys", Fx_rebind_keys, Sx_rebind_keys, 2, 2, 0,
4416 "Rebind KEYCODE to list of strings STRINGS.\n\
4417 STRINGS should be a list of 16 elements, one for each shift combination.\n\
4418 nil as element means don't change.\n\
4419 See the documentation of `x-rebind-key' for more information.")
4420 (keycode, strings)
4421 register Lisp_Object keycode;
4422 register Lisp_Object strings;
4423 {
4424 register Lisp_Object item;
4425 register unsigned char *rawstring;
4426 KeySym rawkey, modifier[1];
4427 int strsize;
4428 register unsigned i;
4429
4430 check_x ();
4431 CHECK_NUMBER (keycode, 1);
4432 CHECK_CONS (strings, 2);
4433 rawkey = (KeySym) ((unsigned) (XINT (keycode))) & 255;
4434 for (i = 0; i <= 15; strings = Fcdr (strings), i++)
4435 {
4436 item = Fcar (strings);
4437 if (!NILP (item))
4438 {
4439 CHECK_STRING (item, 2);
4440 strsize = XSTRING (item)->size;
4441 rawstring = (unsigned char *) xmalloc (strsize);
4442 bcopy (XSTRING (item)->data, rawstring, strsize);
4443 modifier[1] = 1 << i;
4444 XRebindKeysym (x_current_display, rawkey, modifier, 1,
4445 rawstring, strsize);
4446 }
4447 }
4448 return Qnil;
4449 }
4450 #endif /* HAVE_X11 */
4451 #endif /* 0 */
4452 \f
4453 #ifndef HAVE_XSCREENNUMBEROFSCREEN
4454 int
4455 XScreenNumberOfScreen (scr)
4456 register Screen *scr;
4457 {
4458 register Display *dpy;
4459 register Screen *dpyscr;
4460 register int i;
4461
4462 dpy = scr->display;
4463 dpyscr = dpy->screens;
4464
4465 for (i = 0; i < dpy->nscreens; i++, dpyscr++)
4466 if (scr == dpyscr)
4467 return i;
4468
4469 return -1;
4470 }
4471 #endif /* not HAVE_XSCREENNUMBEROFSCREEN */
4472
4473 Visual *
4474 select_visual (dpy, screen, depth)
4475 Display *dpy;
4476 Screen *screen;
4477 unsigned int *depth;
4478 {
4479 Visual *v;
4480 XVisualInfo *vinfo, vinfo_template;
4481 int n_visuals;
4482
4483 v = DefaultVisualOfScreen (screen);
4484
4485 #ifdef HAVE_X11R4
4486 vinfo_template.visualid = XVisualIDFromVisual (v);
4487 #else
4488 vinfo_template.visualid = v->visualid;
4489 #endif
4490
4491 vinfo_template.screen = XScreenNumberOfScreen (screen);
4492
4493 vinfo = XGetVisualInfo (dpy,
4494 VisualIDMask | VisualScreenMask, &vinfo_template,
4495 &n_visuals);
4496 if (n_visuals != 1)
4497 fatal ("Can't get proper X visual info");
4498
4499 if ((1 << vinfo->depth) == vinfo->colormap_size)
4500 *depth = vinfo->depth;
4501 else
4502 {
4503 int i = 0;
4504 int n = vinfo->colormap_size - 1;
4505 while (n)
4506 {
4507 n = n >> 1;
4508 i++;
4509 }
4510 *depth = i;
4511 }
4512
4513 XFree ((char *) vinfo);
4514 return v;
4515 }
4516
4517 /* Return the X display structure for the display named NAME.
4518 Open a new connection if necessary. */
4519
4520 struct x_display_info *
4521 x_display_info_for_name (name)
4522 Lisp_Object name;
4523 {
4524 Lisp_Object names;
4525 struct x_display_info *dpyinfo;
4526
4527 CHECK_STRING (name, 0);
4528
4529 for (dpyinfo = x_display_list, names = x_display_name_list;
4530 dpyinfo;
4531 dpyinfo = dpyinfo->next, names = XCONS (names)->cdr)
4532 {
4533 Lisp_Object tem;
4534 tem = Fstring_equal (XCONS (XCONS (names)->car)->car, name);
4535 if (!NILP (tem))
4536 return dpyinfo;
4537 }
4538
4539 validate_x_resource_name ();
4540
4541 dpyinfo = x_term_init (name, (unsigned char *)0,
4542 XSTRING (Vx_resource_name)->data);
4543
4544 if (dpyinfo == 0)
4545 error ("X server %s not responding", XSTRING (name)->data);
4546
4547 x_in_use = 1;
4548 XSETFASTINT (Vwindow_system_version, 11);
4549
4550 return dpyinfo;
4551 }
4552
4553 DEFUN ("x-open-connection", Fx_open_connection, Sx_open_connection,
4554 1, 3, 0, "Open a connection to an X server.\n\
4555 DISPLAY is the name of the display to connect to.\n\
4556 Optional second arg XRM-STRING is a string of resources in xrdb format.\n\
4557 If the optional third arg MUST-SUCCEED is non-nil,\n\
4558 terminate Emacs if we can't open the connection.")
4559 (display, xrm_string, must_succeed)
4560 Lisp_Object display, xrm_string, must_succeed;
4561 {
4562 unsigned int n_planes;
4563 unsigned char *xrm_option;
4564 struct x_display_info *dpyinfo;
4565
4566 CHECK_STRING (display, 0);
4567 if (! NILP (xrm_string))
4568 CHECK_STRING (xrm_string, 1);
4569
4570 if (! NILP (xrm_string))
4571 xrm_option = (unsigned char *) XSTRING (xrm_string)->data;
4572 else
4573 xrm_option = (unsigned char *) 0;
4574
4575 validate_x_resource_name ();
4576
4577 /* This is what opens the connection and sets x_current_display.
4578 This also initializes many symbols, such as those used for input. */
4579 dpyinfo = x_term_init (display, xrm_option,
4580 XSTRING (Vx_resource_name)->data);
4581
4582 if (dpyinfo == 0)
4583 {
4584 if (!NILP (must_succeed))
4585 fatal ("X server %s not responding.\n\
4586 Check the DISPLAY environment variable or use \"-d\"\n",
4587 XSTRING (display)->data);
4588 else
4589 error ("X server %s not responding", XSTRING (display)->data);
4590 }
4591
4592 x_in_use = 1;
4593
4594 XSETFASTINT (Vwindow_system_version, 11);
4595 return Qnil;
4596 }
4597
4598 DEFUN ("x-close-connection", Fx_close_connection,
4599 Sx_close_connection, 1, 1, 0,
4600 "Close the connection to DISPLAY's X server.\n\
4601 For DISPLAY, specify either a frame or a display name (a string).\n\
4602 If DISPLAY is nil, that stands for the selected frame's display.")
4603 (display)
4604 Lisp_Object display;
4605 {
4606 struct x_display_info *dpyinfo = check_x_display_info (display);
4607 struct x_display_info *tail;
4608 int i;
4609
4610 if (dpyinfo->reference_count > 0)
4611 error ("Display still has frames on it");
4612
4613 BLOCK_INPUT;
4614 /* Free the fonts in the font table. */
4615 for (i = 0; i < dpyinfo->n_fonts; i++)
4616 {
4617 if (dpyinfo->font_table[i].name)
4618 free (dpyinfo->font_table[i].name);
4619 /* Don't free the full_name string;
4620 it is always shared with something else. */
4621 XFreeFont (dpyinfo->display, dpyinfo->font_table[i].font);
4622 }
4623 x_destroy_all_bitmaps (dpyinfo);
4624 XSetCloseDownMode (dpyinfo->display, DestroyAll);
4625
4626 #ifdef USE_X_TOOLKIT
4627 XtCloseDisplay (dpyinfo->display);
4628 #else
4629 XCloseDisplay (dpyinfo->display);
4630 #endif
4631
4632 x_delete_display (dpyinfo);
4633 UNBLOCK_INPUT;
4634
4635 return Qnil;
4636 }
4637
4638 DEFUN ("x-display-list", Fx_display_list, Sx_display_list, 0, 0, 0,
4639 "Return the list of display names that Emacs has connections to.")
4640 ()
4641 {
4642 Lisp_Object tail, result;
4643
4644 result = Qnil;
4645 for (tail = x_display_name_list; ! NILP (tail); tail = XCONS (tail)->cdr)
4646 result = Fcons (XCONS (XCONS (tail)->car)->car, result);
4647
4648 return result;
4649 }
4650
4651 DEFUN ("x-synchronize", Fx_synchronize, Sx_synchronize, 1, 2, 0,
4652 "If ON is non-nil, report X errors as soon as the erring request is made.\n\
4653 If ON is nil, allow buffering of requests.\n\
4654 Turning on synchronization prohibits the Xlib routines from buffering\n\
4655 requests and seriously degrades performance, but makes debugging much\n\
4656 easier.\n\
4657 The optional second argument DISPLAY specifies which display to act on.\n\
4658 DISPLAY should be either a frame or a display name (a string).\n\
4659 If DISPLAY is omitted or nil, that stands for the selected frame's display.")
4660 (on, display)
4661 Lisp_Object display, on;
4662 {
4663 struct x_display_info *dpyinfo = check_x_display_info (display);
4664
4665 XSynchronize (dpyinfo->display, !EQ (on, Qnil));
4666
4667 return Qnil;
4668 }
4669
4670 /* Wait for responses to all X commands issued so far for frame F. */
4671
4672 void
4673 x_sync (f)
4674 FRAME_PTR f;
4675 {
4676 BLOCK_INPUT;
4677 XSync (FRAME_X_DISPLAY (f), False);
4678 UNBLOCK_INPUT;
4679 }
4680 \f
4681 syms_of_xfns ()
4682 {
4683 /* This is zero if not using X windows. */
4684 x_in_use = 0;
4685
4686 /* The section below is built by the lisp expression at the top of the file,
4687 just above where these variables are declared. */
4688 /*&&& init symbols here &&&*/
4689 Qauto_raise = intern ("auto-raise");
4690 staticpro (&Qauto_raise);
4691 Qauto_lower = intern ("auto-lower");
4692 staticpro (&Qauto_lower);
4693 Qbackground_color = intern ("background-color");
4694 staticpro (&Qbackground_color);
4695 Qbar = intern ("bar");
4696 staticpro (&Qbar);
4697 Qborder_color = intern ("border-color");
4698 staticpro (&Qborder_color);
4699 Qborder_width = intern ("border-width");
4700 staticpro (&Qborder_width);
4701 Qbox = intern ("box");
4702 staticpro (&Qbox);
4703 Qcursor_color = intern ("cursor-color");
4704 staticpro (&Qcursor_color);
4705 Qcursor_type = intern ("cursor-type");
4706 staticpro (&Qcursor_type);
4707 Qfont = intern ("font");
4708 staticpro (&Qfont);
4709 Qforeground_color = intern ("foreground-color");
4710 staticpro (&Qforeground_color);
4711 Qgeometry = intern ("geometry");
4712 staticpro (&Qgeometry);
4713 Qicon_left = intern ("icon-left");
4714 staticpro (&Qicon_left);
4715 Qicon_top = intern ("icon-top");
4716 staticpro (&Qicon_top);
4717 Qicon_type = intern ("icon-type");
4718 staticpro (&Qicon_type);
4719 Qinternal_border_width = intern ("internal-border-width");
4720 staticpro (&Qinternal_border_width);
4721 Qleft = intern ("left");
4722 staticpro (&Qleft);
4723 Qmouse_color = intern ("mouse-color");
4724 staticpro (&Qmouse_color);
4725 Qnone = intern ("none");
4726 staticpro (&Qnone);
4727 Qparent_id = intern ("parent-id");
4728 staticpro (&Qparent_id);
4729 Qscroll_bar_width = intern ("scroll-bar-width");
4730 staticpro (&Qscroll_bar_width);
4731 Qsuppress_icon = intern ("suppress-icon");
4732 staticpro (&Qsuppress_icon);
4733 Qtop = intern ("top");
4734 staticpro (&Qtop);
4735 Qundefined_color = intern ("undefined-color");
4736 staticpro (&Qundefined_color);
4737 Qvertical_scroll_bars = intern ("vertical-scroll-bars");
4738 staticpro (&Qvertical_scroll_bars);
4739 Qvisibility = intern ("visibility");
4740 staticpro (&Qvisibility);
4741 Qwindow_id = intern ("window-id");
4742 staticpro (&Qwindow_id);
4743 Qx_frame_parameter = intern ("x-frame-parameter");
4744 staticpro (&Qx_frame_parameter);
4745 Qx_resource_name = intern ("x-resource-name");
4746 staticpro (&Qx_resource_name);
4747 Quser_position = intern ("user-position");
4748 staticpro (&Quser_position);
4749 Quser_size = intern ("user-size");
4750 staticpro (&Quser_size);
4751 Qdisplay = intern ("display");
4752 staticpro (&Qdisplay);
4753 /* This is the end of symbol initialization. */
4754
4755 Fput (Qundefined_color, Qerror_conditions,
4756 Fcons (Qundefined_color, Fcons (Qerror, Qnil)));
4757 Fput (Qundefined_color, Qerror_message,
4758 build_string ("Undefined color"));
4759
4760 init_x_parm_symbols ();
4761
4762 DEFVAR_LISP ("x-bitmap-file-path", &Vx_bitmap_file_path,
4763 "List of directories to search for bitmap files for X.");
4764 Vx_bitmap_file_path = Fcons (build_string (PATH_BITMAPS), Qnil);
4765
4766 DEFVAR_LISP ("x-pointer-shape", &Vx_pointer_shape,
4767 "The shape of the pointer when over text.\n\
4768 Changing the value does not affect existing frames\n\
4769 unless you set the mouse color.");
4770 Vx_pointer_shape = Qnil;
4771
4772 DEFVAR_LISP ("x-resource-name", &Vx_resource_name,
4773 "The name Emacs uses to look up X resources; for internal use only.\n\
4774 `x-get-resource' uses this as the first component of the instance name\n\
4775 when requesting resource values.\n\
4776 Emacs initially sets `x-resource-name' to the name under which Emacs\n\
4777 was invoked, or to the value specified with the `-name' or `-rn'\n\
4778 switches, if present.");
4779 Vx_resource_name = Qnil;
4780
4781 #if 0 /* This doesn't really do anything. */
4782 DEFVAR_INT ("x-nontext-pointer-shape", &Vx_nontext_pointer_shape,
4783 "The shape of the pointer when not over text.\n\
4784 This variable takes effect when you create a new frame\n\
4785 or when you set the mouse color.");
4786 #endif
4787 Vx_nontext_pointer_shape = Qnil;
4788
4789 #if 0 /* This doesn't really do anything. */
4790 DEFVAR_INT ("x-mode-pointer-shape", &Vx_mode_pointer_shape,
4791 "The shape of the pointer when over the mode line.\n\
4792 This variable takes effect when you create a new frame\n\
4793 or when you set the mouse color.");
4794 #endif
4795 Vx_mode_pointer_shape = Qnil;
4796
4797 DEFVAR_INT ("x-sensitive-text-pointer-shape",
4798 &Vx_sensitive_text_pointer_shape,
4799 "The shape of the pointer when over mouse-sensitive text.\n\
4800 This variable takes effect when you create a new frame\n\
4801 or when you set the mouse color.");
4802 Vx_sensitive_text_pointer_shape = Qnil;
4803
4804 DEFVAR_LISP ("x-cursor-fore-pixel", &Vx_cursor_fore_pixel,
4805 "A string indicating the foreground color of the cursor box.");
4806 Vx_cursor_fore_pixel = Qnil;
4807
4808 DEFVAR_LISP ("x-no-window-manager", &Vx_no_window_manager,
4809 "Non-nil if no X window manager is in use.");
4810
4811 #ifdef USE_X_TOOLKIT
4812 Fprovide (intern ("x-toolkit"));
4813 #endif
4814
4815 defsubr (&Sx_get_resource);
4816 #if 0
4817 defsubr (&Sx_draw_rectangle);
4818 defsubr (&Sx_erase_rectangle);
4819 defsubr (&Sx_contour_region);
4820 defsubr (&Sx_uncontour_region);
4821 #endif
4822 defsubr (&Sx_list_fonts);
4823 defsubr (&Sx_display_color_p);
4824 defsubr (&Sx_display_grayscale_p);
4825 defsubr (&Sx_color_defined_p);
4826 defsubr (&Sx_color_values);
4827 defsubr (&Sx_server_max_request_size);
4828 defsubr (&Sx_server_vendor);
4829 defsubr (&Sx_server_version);
4830 defsubr (&Sx_display_pixel_width);
4831 defsubr (&Sx_display_pixel_height);
4832 defsubr (&Sx_display_mm_width);
4833 defsubr (&Sx_display_mm_height);
4834 defsubr (&Sx_display_screens);
4835 defsubr (&Sx_display_planes);
4836 defsubr (&Sx_display_color_cells);
4837 defsubr (&Sx_display_visual_class);
4838 defsubr (&Sx_display_backing_store);
4839 defsubr (&Sx_display_save_under);
4840 #if 0
4841 defsubr (&Sx_rebind_key);
4842 defsubr (&Sx_rebind_keys);
4843 defsubr (&Sx_track_pointer);
4844 defsubr (&Sx_grab_pointer);
4845 defsubr (&Sx_ungrab_pointer);
4846 #endif
4847 defsubr (&Sx_parse_geometry);
4848 defsubr (&Sx_create_frame);
4849 defsubr (&Sfocus_frame);
4850 defsubr (&Sunfocus_frame);
4851 #if 0
4852 defsubr (&Sx_horizontal_line);
4853 #endif
4854 defsubr (&Sx_open_connection);
4855 defsubr (&Sx_close_connection);
4856 defsubr (&Sx_display_list);
4857 defsubr (&Sx_synchronize);
4858 }
4859
4860 #endif /* HAVE_X_WINDOWS */