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