XEmacs 21.2.30 "Hygeia".
[chise/xemacs-chise.git.1] / src / frame.c
1 /* Generic frame functions.
2    Copyright (C) 1989, 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
3    Copyright (C) 1995, 1996 Ben Wing.
4    Copyright (C) 1995 Sun Microsystems, Inc.
5
6 This file is part of XEmacs.
7
8 XEmacs is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by the
10 Free Software Foundation; either version 2, or (at your option) any
11 later version.
12
13 XEmacs is distributed in the hope that it will be useful, but WITHOUT
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
16 for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with XEmacs; see the file COPYING.  If not, write to
20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA.  */
22
23 /* Synched up with: FSF 19.30. */
24
25 /* This file has been Mule-ized. */
26
27 #include <config.h>
28 #include "lisp.h"
29
30 #include "buffer.h"             /* for Vbuffer_alist */
31 #include "console.h"
32 #include "events.h"
33 #include "extents.h"
34 #include "faces.h"
35 #include "frame.h"
36 #include "glyphs.h"
37 #include "gutter.h"
38 #include "menubar.h"
39 #include "redisplay.h"
40 #include "scrollbar.h"
41 #include "window.h"
42
43 Lisp_Object Vselect_frame_hook, Qselect_frame_hook;
44 Lisp_Object Vdeselect_frame_hook, Qdeselect_frame_hook;
45 Lisp_Object Vcreate_frame_hook, Qcreate_frame_hook;
46 Lisp_Object Vdelete_frame_hook, Qdelete_frame_hook;
47 Lisp_Object Vmouse_enter_frame_hook, Qmouse_enter_frame_hook;
48 Lisp_Object Vmouse_leave_frame_hook, Qmouse_leave_frame_hook;
49 Lisp_Object Vmap_frame_hook, Qmap_frame_hook;
50 Lisp_Object Vunmap_frame_hook, Qunmap_frame_hook;
51 int  allow_deletion_of_last_visible_frame;
52 Lisp_Object Vadjust_frame_function;
53 Lisp_Object Vmouse_motion_handler;
54 Lisp_Object Vsynchronize_minibuffers;
55 Lisp_Object Qsynchronize_minibuffers;
56 Lisp_Object Qbuffer_predicate;
57 Lisp_Object Qmake_initial_minibuffer_frame;
58 Lisp_Object Qcustom_initialize_frame;
59
60 /* We declare all these frame properties here even though many of them
61    are currently only used in frame-x.c, because we should generalize
62    them. */
63
64 Lisp_Object Qminibuffer;
65 Lisp_Object Qunsplittable;
66 Lisp_Object Qinternal_border_width;
67 Lisp_Object Qtop_toolbar_shadow_color;
68 Lisp_Object Qbottom_toolbar_shadow_color;
69 Lisp_Object Qbackground_toolbar_color;
70 Lisp_Object Qtop_toolbar_shadow_pixmap;
71 Lisp_Object Qbottom_toolbar_shadow_pixmap;
72 Lisp_Object Qtoolbar_shadow_thickness;
73 Lisp_Object Qscrollbar_placement;
74 Lisp_Object Qinter_line_space;
75 Lisp_Object Qvisual_bell;
76 Lisp_Object Qbell_volume;
77 Lisp_Object Qpointer_background;
78 Lisp_Object Qpointer_color;
79 Lisp_Object Qtext_pointer;
80 Lisp_Object Qspace_pointer;
81 Lisp_Object Qmodeline_pointer;
82 Lisp_Object Qgc_pointer;
83 Lisp_Object Qinitially_unmapped;
84 Lisp_Object Quse_backing_store;
85 Lisp_Object Qborder_color;
86 Lisp_Object Qborder_width;
87
88 Lisp_Object Qframep, Qframe_live_p;
89 Lisp_Object Qdelete_frame;
90
91 Lisp_Object Qframe_title_format, Vframe_title_format;
92 Lisp_Object Qframe_icon_title_format, Vframe_icon_title_format;
93
94 Lisp_Object Vdefault_frame_name;
95 Lisp_Object Vdefault_frame_plist;
96
97 Lisp_Object Vframe_icon_glyph;
98
99 Lisp_Object Qhidden;
100
101 Lisp_Object Qvisible, Qiconic, Qinvisible, Qvisible_iconic, Qinvisible_iconic;
102 Lisp_Object Qnomini, Qvisible_nomini, Qiconic_nomini, Qinvisible_nomini;
103 Lisp_Object Qvisible_iconic_nomini, Qinvisible_iconic_nomini;
104
105 Lisp_Object Qset_specifier, Qset_glyph_image, Qset_face_property;
106 Lisp_Object Qface_property_instance;
107
108 Lisp_Object Qframe_property_alias;
109
110 /* If this is non-nil, it is the frame that make-frame is currently
111    creating.  We can't set the current frame to this in case the
112    debugger goes off because it would try and display to it.  However,
113    there are some places which need to reference it which have no
114    other way of getting it if it isn't the selected frame. */
115 Lisp_Object Vframe_being_created;
116 Lisp_Object Qframe_being_created;
117
118 static void store_minibuf_frame_prop (struct frame *f, Lisp_Object val);
119 static struct display_line title_string_display_line;
120 /* Used by generate_title_string. Global because they get used so much that
121    the dynamic allocation time adds up. */
122 static Emchar_dynarr *title_string_emchar_dynarr;
123
124 \f
125 static Lisp_Object
126 mark_frame (Lisp_Object obj)
127 {
128   struct frame *f = XFRAME (obj);
129
130 #define MARKED_SLOT(x) mark_object (f->x)
131 #include "frameslots.h"
132
133   mark_subwindow_cachels (f->subwindow_cachels);
134
135   if (FRAME_LIVE_P (f)) /* device is nil for a dead frame */
136     MAYBE_FRAMEMETH (f, mark_frame, (f));
137
138   return Qnil;
139 }
140
141 static void
142 print_frame (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
143 {
144   struct frame *frm = XFRAME (obj);
145   char buf[200];
146
147   if (print_readably)
148     error ("printing unreadable object #<frame %s 0x%x>",
149            XSTRING_DATA (frm->name), frm->header.uid);
150
151   sprintf (buf, "#<%s-frame ", !FRAME_LIVE_P (frm) ? "dead" :
152            FRAME_TYPE_NAME (frm));
153   write_c_string (buf, printcharfun);
154   print_internal (frm->name, printcharfun, 1);
155   sprintf (buf, " 0x%x>", frm->header.uid);
156   write_c_string (buf, printcharfun);
157 }
158
159 DEFINE_LRECORD_IMPLEMENTATION ("frame", frame,
160                                mark_frame, print_frame, 0, 0, 0, 0,
161                                struct frame);
162 \f
163 static void
164 nuke_all_frame_slots (struct frame *f)
165 {
166 #define MARKED_SLOT(x)  f->x = Qnil
167 #include "frameslots.h"
168 }
169
170 /* Allocate a new frame object and set all its fields to reasonable
171    values.  The root window is created but the minibuffer will be done
172    later. */
173
174 static struct frame *
175 allocate_frame_core (Lisp_Object device)
176 {
177   /* This function can GC */
178   Lisp_Object frame;
179   Lisp_Object root_window;
180   struct frame *f = alloc_lcrecord_type (struct frame, &lrecord_frame);
181
182   zero_lcrecord (f);
183   nuke_all_frame_slots (f);
184   XSETFRAME (frame, f);
185
186   f->device = device;
187   f->framemeths = XDEVICE (device)->devmeths;
188   f->buffer_alist = Fcopy_sequence (Vbuffer_alist);
189
190   root_window = allocate_window ();
191   XWINDOW (root_window)->frame = frame;
192
193   /* 10 is arbitrary,
194      Just so that there is "something there."
195      Correct size will be set up later with change_frame_size.  */
196
197   f->width  = 10;
198   f->height = 10;
199
200   XWINDOW (root_window)->pixel_width = 10;
201   XWINDOW (root_window)->pixel_height = 9;
202
203   /* The size of the minibuffer window is now set in x_create_frame
204      in xfns.c. */
205
206   f->root_window = root_window;
207   f->selected_window = root_window;
208   f->last_nonminibuf_window = root_window;
209
210   /* cache of subwindows visible on frame */
211   f->subwindow_cachels    = Dynarr_new (subwindow_cachel);
212
213   /* associated exposure ignore list */
214   f->subwindow_exposures = 0;
215   f->subwindow_exposures_tail = 0;
216
217   FRAME_SET_PAGENUMBER (f, 1);
218
219   /* Choose a buffer for the frame's root window.  */
220   XWINDOW (root_window)->buffer = Qt;
221   {
222     Lisp_Object buf;
223
224     buf = Fcurrent_buffer ();
225     /* If buf is a 'hidden' buffer (i.e. one whose name starts with
226        a space), try to find another one.  */
227     if (string_char (XSTRING (Fbuffer_name (buf)), 0) == ' ')
228       buf = Fother_buffer (buf, Qnil, Qnil);
229     Fset_window_buffer (root_window, buf, Qnil);
230   }
231
232   return f;
233 }
234
235 static void
236 setup_normal_frame (struct frame *f)
237 {
238   Lisp_Object mini_window;
239   Lisp_Object frame;
240
241   XSETFRAME (frame, f);
242
243   mini_window = allocate_window ();
244   XWINDOW (f->root_window)->next = mini_window;
245   XWINDOW (mini_window)->prev = f->root_window;
246   XWINDOW (mini_window)->mini_p = Qt;
247   XWINDOW (mini_window)->frame = frame;
248   f->minibuffer_window = mini_window;
249   f->has_minibuffer = 1;
250
251   XWINDOW (mini_window)->buffer = Qt;
252   Fset_window_buffer (mini_window, Vminibuffer_zero, Qt);
253 }
254
255 /* Make a frame using a separate minibuffer window on another frame.
256    MINI_WINDOW is the minibuffer window to use.  nil means use the
257    default-minibuffer-frame.  */
258
259 static void
260 setup_frame_without_minibuffer (struct frame *f, Lisp_Object mini_window)
261 {
262   /* This function can GC */
263   Lisp_Object device = f->device;
264
265   if (!NILP (mini_window))
266     CHECK_LIVE_WINDOW (mini_window);
267
268   if (!NILP (mini_window)
269       && !EQ (DEVICE_CONSOLE (XDEVICE (device)),
270               FRAME_CONSOLE (XFRAME (XWINDOW (mini_window)->frame))))
271     error ("frame and minibuffer must be on the same console");
272
273   if (NILP (mini_window))
274     {
275       struct console *con = XCONSOLE (FRAME_CONSOLE (f));
276       /* Use default-minibuffer-frame if possible.  */
277       if (!FRAMEP (con->default_minibuffer_frame)
278           || ! FRAME_LIVE_P (XFRAME (con->default_minibuffer_frame)))
279         {
280           /* If there's no minibuffer frame to use, create one.  */
281           con->default_minibuffer_frame
282             = call1 (Qmake_initial_minibuffer_frame, device);
283         }
284       mini_window = XFRAME (con->default_minibuffer_frame)->minibuffer_window;
285     }
286
287   /* Install the chosen minibuffer window, with proper buffer.  */
288   store_minibuf_frame_prop (f, mini_window);
289   Fset_window_buffer (mini_window, Vminibuffer_zero, Qt);
290 }
291
292 /* Make a frame containing only a minibuffer window.  */
293
294 static void
295 setup_minibuffer_frame (struct frame *f)
296 {
297   /* This function can GC */
298   /* First make a frame containing just a root window, no minibuffer.  */
299   Lisp_Object mini_window;
300   Lisp_Object frame;
301
302   XSETFRAME (frame, f);
303
304   f->no_split = 1;
305   f->has_minibuffer = 1;
306
307   /* Now label the root window as also being the minibuffer.
308      Avoid infinite looping on the window chain by marking next pointer
309      as nil. */
310
311   mini_window = f->minibuffer_window = f->root_window;
312   XWINDOW (mini_window)->mini_p = Qt;
313   XWINDOW (mini_window)->next   = Qnil;
314   XWINDOW (mini_window)->prev   = Qnil;
315   XWINDOW (mini_window)->frame  = frame;
316
317   /* Put the proper buffer in that window.  */
318
319   Fset_window_buffer (mini_window, Vminibuffer_zero, Qt);
320 }
321
322 static Lisp_Object
323 make_sure_its_a_fresh_plist (Lisp_Object foolist)
324 {
325   if (CONSP (Fcar (foolist)))
326     {
327       /* looks like an alist to me. */
328       foolist = Fcopy_alist (foolist);
329       foolist = Fdestructive_alist_to_plist (foolist);
330     }
331   else
332     foolist = Fcopy_sequence (foolist);
333
334   return foolist;
335 }
336
337 DEFUN ("make-frame", Fmake_frame, 0, 2, "", /*
338 Create and return a new frame, displaying the current buffer.
339 Runs the functions listed in `create-frame-hook' after frame creation.
340
341 Optional argument PROPS is a property list (a list of alternating
342 keyword-value specifications) of properties for the new frame.
343 \(An alist is accepted for backward compatibility but should not
344 be passed in.)
345
346 See `set-frame-properties', `default-x-frame-plist', and
347 `default-tty-frame-plist' for the specially-recognized properties.
348 */
349        (props, device))
350 {
351   struct frame *f;
352   struct device *d;
353   Lisp_Object frame = Qnil, name = Qnil, minibuf;
354   struct gcpro gcpro1, gcpro2, gcpro3;
355   int speccount = specpdl_depth ();
356   int first_frame_on_device = 0;
357   int first_frame_on_console = 0;
358
359   d = decode_device (device);
360   XSETDEVICE (device, d);
361
362   /* PROPS and NAME may be freshly-created, so make sure to GCPRO. */
363   GCPRO3 (frame, props, name);
364
365   props = make_sure_its_a_fresh_plist (props);
366   if (DEVICE_SPECIFIC_FRAME_PROPS (d))
367     /* Put the device-specific props before the more general ones so
368        that they override them. */
369     props = nconc2 (props,
370                     make_sure_its_a_fresh_plist
371                     (*DEVICE_SPECIFIC_FRAME_PROPS (d)));
372   props = nconc2 (props, make_sure_its_a_fresh_plist (Vdefault_frame_plist));
373   Fcanonicalize_lax_plist (props, Qnil);
374
375   name = Flax_plist_get (props, Qname, Qnil);
376   if (!NILP (name))
377     CHECK_STRING (name);
378   else if (STRINGP (Vdefault_frame_name))
379     name = Vdefault_frame_name;
380   else
381     name = build_string ("emacs");
382
383   if (!NILP (Fstring_match (make_string ((const Bufbyte *) "\\.", 2), name,
384                             Qnil, Qnil)))
385     signal_simple_error (". not allowed in frame names", name);
386
387   f = allocate_frame_core (device);
388   XSETFRAME (frame, f);
389
390   specbind (Qframe_being_created, name);
391   f->name = name;
392
393   FRAMEMETH (f, init_frame_1, (f, props));
394
395   minibuf = Flax_plist_get (props, Qminibuffer, Qunbound);
396   if (UNBOUNDP (minibuf))
397     {
398       /* If minibuf is unspecified, then look for a minibuffer X resource. */
399       /* #### Not implemented any more.  We need to fix things up so
400          that we search out all X resources and append them to the end of
401          props, above.  This is the only way in general to assure
402          coherent behavior for all frame properties/resources/etc. */
403     }
404   else
405     props = Flax_plist_remprop (props, Qminibuffer);
406
407   if (EQ (minibuf, Qnone) || NILP (minibuf))
408     setup_frame_without_minibuffer (f, Qnil);
409   else if (EQ (minibuf, Qonly))
410     setup_minibuffer_frame (f);
411   else if (WINDOWP (minibuf))
412     setup_frame_without_minibuffer (f, minibuf);
413   else if (EQ (minibuf, Qt) || UNBOUNDP (minibuf))
414     setup_normal_frame (f);
415   else
416     signal_simple_error ("Invalid value for `minibuffer'", minibuf);
417
418   update_frame_window_mirror (f);
419
420   if (initialized && !DEVICE_STREAM_P (d))
421     {
422       if (!NILP (f->minibuffer_window))
423         reset_face_cachels (XWINDOW (f->minibuffer_window));
424       reset_face_cachels (XWINDOW (f->root_window));
425     }
426
427   /* If no frames on this device formerly existed, say this is the
428      first frame.  It kind of assumes that frameless devices don't
429      exist, but it shouldn't be too harmful.  */
430   if (NILP (DEVICE_FRAME_LIST (d)))
431     first_frame_on_device = 1;
432
433   /* This *must* go before the init_*() methods.  Those functions
434      call Lisp code, and if any of them causes a warning to be displayed
435      and the *Warnings* buffer to be created, it won't get added to
436      the frame-specific version of the buffer-alist unless the frame
437      is accessible from the device. */
438
439 #if 0
440   DEVICE_FRAME_LIST (d) = nconc2 (DEVICE_FRAME_LIST (d), Fcons (frame, Qnil));
441 #endif
442   DEVICE_FRAME_LIST (d) = Fcons (frame, DEVICE_FRAME_LIST (d));
443   RESET_CHANGED_SET_FLAGS;
444
445   /* Now make sure that the initial cached values are set correctly.
446      Do this after the init_frame method is called because that may
447      do things (e.g. create widgets) that are necessary for the
448      specifier value-changed methods to work OK. */
449   recompute_all_cached_specifiers_in_frame (f);
450
451   if (!DEVICE_STREAM_P (d))
452     {
453       init_frame_faces (f);
454
455 #ifdef HAVE_SCROLLBARS
456       /* Finish up resourcing the scrollbars. */
457       init_frame_scrollbars (f);
458 #endif
459
460 #ifdef HAVE_TOOLBARS
461       /* Create the initial toolbars.  We have to do this after the frame
462          methods are called because it may potentially call some things itself
463          which depend on the normal frame methods having initialized
464          things. */
465       init_frame_toolbars (f);
466 #endif
467       reset_face_cachels (XWINDOW (FRAME_SELECTED_WINDOW (f)));
468       reset_glyph_cachels (XWINDOW (FRAME_SELECTED_WINDOW (f)));
469       reset_subwindow_cachels (f);
470       change_frame_size (f, f->height, f->width, 0);
471
472     }
473
474   MAYBE_FRAMEMETH (f, init_frame_2, (f, props));
475   Fset_frame_properties (frame, props);
476   MAYBE_FRAMEMETH (f, init_frame_3, (f));
477
478   /* now initialise the gutters, this won't change the frame size
479      so is ok here. */
480   if (!DEVICE_STREAM_P (d))
481     init_frame_gutters (f);
482
483   /* Hallelujah, praise the lord. */
484   f->init_finished = 1;
485
486   /* If this is the first frame on the device, make it the selected one. */
487   if (first_frame_on_device && NILP (DEVICE_SELECTED_FRAME (d)))
488     set_device_selected_frame (d, frame);
489
490   /* If at startup or if the current console is a stream console
491      (usually also at startup), make this console the selected one
492      so that messages show up on it. */
493   if (NILP (Fselected_console ()) ||
494       CONSOLE_STREAM_P (XCONSOLE (Fselected_console ())))
495     Fselect_console (DEVICE_CONSOLE (d));
496
497   first_frame_on_console =
498     (first_frame_on_device &&
499      XINT (Flength (CONSOLE_DEVICE_LIST (XCONSOLE (DEVICE_CONSOLE (d)))))
500      == 1);
501
502   /* #### all this calling of frame methods at various odd times
503      is somewhat of a mess.  It's necessary to do it this way due
504      to strange console-type-specific things that need to be done. */
505   MAYBE_FRAMEMETH (f, after_init_frame, (f, first_frame_on_device,
506                                          first_frame_on_console));
507
508   if (first_frame_on_device)
509     {
510       if (first_frame_on_console)
511         va_run_hook_with_args (Qcreate_console_hook, 1, DEVICE_CONSOLE (d));
512       va_run_hook_with_args (Qcreate_device_hook, 1, device);
513     }
514   va_run_hook_with_args (Qcreate_frame_hook, 1, frame);
515
516   /* Initialize custom-specific stuff. */
517   if (!UNBOUNDP (symbol_function (XSYMBOL (Qcustom_initialize_frame))))
518     call1 (Qcustom_initialize_frame, frame);
519
520   unbind_to (speccount, Qnil);
521
522   UNGCPRO;
523   return frame;
524 }
525
526 \f
527 /* this function should be used in most cases when a Lisp function is passed
528    a FRAME argument.  Use this unless you don't accept nil == current frame
529    (in which case, do a CHECK_LIVE_FRAME() and then an XFRAME()) or you
530    allow dead frames.  Note that very few functions should accept dead
531    frames.  It could be argued that functions should just do nothing when
532    given a dead frame, but the presence of a dead frame usually indicates
533    an oversight in the Lisp code that could potentially lead to strange
534    results and so it is better to catch the error early.
535
536    If you only accept X frames, use decode_x_frame(), which does what this
537    function does but also makes sure the frame is an X frame. */
538
539 struct frame *
540 decode_frame (Lisp_Object frame)
541 {
542   if (NILP (frame))
543     return selected_frame ();
544
545   CHECK_LIVE_FRAME (frame);
546   return XFRAME (frame);
547 }
548
549 struct frame *
550 decode_frame_or_selected (Lisp_Object cdf)
551 {
552   if (CONSOLEP (cdf))
553     cdf = CONSOLE_SELECTED_DEVICE (decode_console (cdf));
554   if (DEVICEP (cdf))
555     cdf = DEVICE_SELECTED_FRAME (decode_device (cdf));
556   return decode_frame (cdf);
557 }
558
559 Lisp_Object
560 make_frame (struct frame *f)
561 {
562   Lisp_Object frame;
563   XSETFRAME (frame, f);
564   return frame;
565 }
566
567 \f
568 /*
569  * window size changes are held up during critical regions.  Afterwards,
570  * we want to deal with any delayed changes.
571  */
572 void
573 hold_frame_size_changes (void)
574 {
575   in_display = 1;
576 }
577
578 void
579 unhold_one_frame_size_changes (struct frame *f)
580 {
581   in_display = 0;
582
583   if (f->size_change_pending)
584     change_frame_size (f, f->new_height, f->new_width, 0);
585 }
586
587 void
588 unhold_frame_size_changes (void)
589 {
590   Lisp_Object frmcons, devcons, concons;
591
592   FRAME_LOOP_NO_BREAK (frmcons, devcons, concons)
593     unhold_one_frame_size_changes (XFRAME (XCAR (frmcons)));
594 }
595
596 void
597 invalidate_vertical_divider_cache_in_frame (struct frame *f)
598 {
599   /* Invalidate cached value of needs_vertical_divider_p in
600      every and all windows */
601   map_windows (f, invalidate_vertical_divider_cache_in_window, 0);
602 }
603 \f
604 /*
605  * Frame size may change due to changes in scrollbars, toolbars,
606  * default font etc. These changes are applied early in redisplay
607  * frame.
608  */
609 void
610 adjust_frame_size (struct frame *f)
611 {
612   int keep_char_size = 0;
613   Lisp_Object frame;
614   XSETFRAME (frame, f);
615
616   if (!f->size_slipped)
617     return;
618
619   /* Don't adjust tty frames. #### May break when TTY have menubars.
620      Then, write an Vadjust_frame_function which will return t for TTY
621      frames. Another solution is frame_size_fixed_p method for TTYs,
622      which always returned yes it's fixed.
623   */
624   if (!FRAME_WIN_P (f))
625     {
626       CLEAR_FRAME_SIZE_SLIPPED (f);
627       return;
628     }
629
630   /* frame_size_fixed_p tells that frame size cannot currently
631      be changed change due to external conditions */
632   if (!FRAMEMETH_OR_GIVEN (f, frame_size_fixed_p, (f), 0))
633     {
634       if (NILP (Vadjust_frame_function))
635         keep_char_size = 1;
636       else if (EQ (Vadjust_frame_function, Qt))
637         keep_char_size = 0;
638       else
639         keep_char_size =
640           NILP (call1_trapping_errors ("Error in adjust-frame-function",
641                                        Vadjust_frame_function, frame));
642
643       if (keep_char_size)
644         Fset_frame_size (frame, make_int (FRAME_CHARWIDTH(f)),
645                          make_int (FRAME_CHARHEIGHT(f)), Qnil);
646     }
647
648   if (!keep_char_size)
649     {
650       int height, width;
651       pixel_to_char_size (f, FRAME_PIXWIDTH(f), FRAME_PIXHEIGHT(f),
652                           &width, &height);
653       change_frame_size (f, height, width, 0);
654       CLEAR_FRAME_SIZE_SLIPPED (f);
655     }
656 }
657
658 /*
659  * This is a "specifier changed in frame" handler for various specifiers
660  * changing which causes frame size adjustment
661  */
662 void
663 frame_size_slipped (Lisp_Object specifier, struct frame *f,
664                     Lisp_Object oldval)
665 {
666   MARK_FRAME_SIZE_SLIPPED(f);
667 }
668 \f
669 DEFUN ("framep", Fframep, 1, 1, 0, /*
670 Return non-nil if OBJECT is a frame.
671 Also see `frame-live-p'.
672 Note that FSF Emacs kludgily returns a value indicating what type of
673 frame this is.  Use the cleaner function `frame-type' for that.
674 */
675        (object))
676 {
677   return FRAMEP (object) ? Qt : Qnil;
678 }
679
680 DEFUN ("frame-live-p", Fframe_live_p, 1, 1, 0, /*
681 Return non-nil if OBJECT is a frame which has not been deleted.
682 */
683        (object))
684 {
685   return FRAMEP (object) && FRAME_LIVE_P (XFRAME (object)) ? Qt : Qnil;
686 }
687
688 \f
689 DEFUN ("focus-frame", Ffocus_frame, 1, 1, 0, /*
690 Select FRAME and give it the window system focus.
691 This function is not affected by the value of `focus-follows-mouse'.
692 */
693        (frame))
694 {
695   CHECK_LIVE_FRAME (frame);
696
697   MAYBE_DEVMETH (XDEVICE (FRAME_DEVICE (XFRAME (frame))), focus_on_frame,
698                  (XFRAME (frame)));
699   /* FRAME will be selected by the time we receive the next event.
700      However, it is better to select it explicitly now, in case the
701      Lisp code depends on frame being selected.  */
702   Fselect_frame (frame);
703   return Qnil;
704 }
705
706 /* Called from Fselect_window() */
707 void
708 select_frame_1 (Lisp_Object frame)
709 {
710   struct frame *f = XFRAME (frame);
711   Lisp_Object old_selected_frame = Fselected_frame (Qnil);
712
713   if (EQ (frame, old_selected_frame))
714     return;
715
716   /* now select the frame's device */
717   set_device_selected_frame (XDEVICE (FRAME_DEVICE (f)), frame);
718   select_device_1 (FRAME_DEVICE (f));
719
720   update_frame_window_mirror (f);
721 }
722
723 DEFUN ("select-frame", Fselect_frame, 1, 1, 0, /*
724 Select the frame FRAME.
725 Subsequent editing commands apply to its selected window.
726 The selection of FRAME lasts until the next time the user does
727 something to select a different frame, or until the next time this
728 function is called.
729
730 Note that this does not actually cause the window-system focus to be
731 set to this frame, or the `select-frame-hook' or `deselect-frame-hook'
732 to be run, until the next time that XEmacs is waiting for an event.
733
734 Also note that when focus-follows-mouse is non-nil, the frame
735 selection is temporary and is reverted when the current command
736 terminates, much like the buffer selected by `set-buffer'.  In order
737 to effect a permanent focus change, use `focus-frame'.
738 */
739        (frame))
740 {
741   CHECK_LIVE_FRAME (frame);
742
743   /* select the frame's selected window.  This will call
744      selected_frame_1(). */
745   Fselect_window (FRAME_SELECTED_WINDOW (XFRAME (frame)), Qnil);
746
747   /* Nothing should be depending on the return value of this function.
748      But, of course, there is stuff out there which is. */
749   return frame;
750 }
751
752 /* use this to retrieve the currently selected frame.  You should use
753    this in preference to Fselected_frame (Qnil) unless you are prepared
754    to handle the possibility of there being no selected frame (this
755    happens at some points during startup). */
756
757 struct frame *
758 selected_frame (void)
759 {
760   Lisp_Object device = Fselected_device (Qnil);
761   Lisp_Object frame = DEVICE_SELECTED_FRAME (XDEVICE (device));
762   if (NILP (frame))
763     signal_simple_error ("No frames exist on device", device);
764   return XFRAME (frame);
765 }
766
767 /* use this instead of XFRAME (DEVICE_SELECTED_FRAME (d)) to catch
768    the possibility of there being no frames on the device (just created).
769    There is no point doing this inside of redisplay because errors
770    cause an abort(), indicating a flaw in the logic, and error_check_frame()
771    will catch this just as well. */
772
773 struct frame *
774 device_selected_frame (struct device *d)
775 {
776   Lisp_Object frame = DEVICE_SELECTED_FRAME (d);
777   if (NILP (frame))
778     {
779       Lisp_Object device;
780       XSETDEVICE (device, d);
781       signal_simple_error ("No frames exist on device", device);
782     }
783   return XFRAME (frame);
784 }
785
786 #if 0 /* FSFmacs */
787
788 xxDEFUN ("handle-switch-frame", Fhandle_switch_frame, 1, 2, "e", /*
789 Handle a switch-frame event EVENT.
790 Switch-frame events are usually bound to this function.
791 A switch-frame event tells Emacs that the window manager has requested
792 that the user's events be directed to the frame mentioned in the event.
793 This function selects the selected window of the frame of EVENT.
794
795 If EVENT is frame object, handle it as if it were a switch-frame event
796 to that frame.
797 */
798          (frame, no_enter))
799 {
800   /* Preserve prefix arg that the command loop just cleared.  */
801   XCONSOLE (Vselected_console)->prefix_arg = Vcurrent_prefix_arg;
802 #if 0 /* unclean! */
803   run_hook (Qmouse_leave_buffer_hook);
804 #endif
805   return do_switch_frame (frame, no_enter, 0);
806 }
807
808 /* A load of garbage. */
809 xxDEFUN ("ignore-event", Fignore_event, 0, 0, "", /*
810 Do nothing, but preserve any prefix argument already specified.
811 This is a suitable binding for iconify-frame and make-frame-visible.
812 */
813          ())
814 {
815   struct console *c = XCONSOLE (Vselected_console);
816
817   c->prefix_arg = Vcurrent_prefix_arg;
818   return Qnil;
819 }
820
821 #endif /* 0 */
822
823 DEFUN ("selected-frame", Fselected_frame, 0, 1, 0, /*
824 Return the frame that is now selected on device DEVICE.
825 If DEVICE is not specified, the selected device will be used.
826 If no frames exist on the device, nil is returned.
827 */
828        (device))
829 {
830   if (NILP (device) && NILP (Fselected_device (Qnil)))
831     return Qnil; /* happens early in temacs */
832   return DEVICE_SELECTED_FRAME (decode_device (device));
833 }
834
835 Lisp_Object
836 frame_first_window (struct frame *f)
837 {
838   Lisp_Object w = f->root_window;
839
840   while (1)
841     {
842       if (! NILP (XWINDOW (w)->hchild))
843         w = XWINDOW (w)->hchild;
844       else if (! NILP (XWINDOW (w)->vchild))
845         w = XWINDOW (w)->vchild;
846       else
847         break;
848     }
849
850   return w;
851 }
852
853 DEFUN ("active-minibuffer-window", Factive_minibuffer_window, 0, 0, 0, /*
854 Return the currently active minibuffer window, or nil if none.
855 */
856        ())
857 {
858   return minibuf_level ? minibuf_window : Qnil;
859 }
860
861 DEFUN ("last-nonminibuf-frame", Flast_nonminibuf_frame, 0, 1, 0, /*
862 Return the most-recently-selected non-minibuffer-only frame on CONSOLE.
863 This will always be the same as (selected-frame device) unless the
864 selected frame is a minibuffer-only frame.
865 CONSOLE defaults to the selected console if omitted.
866 */
867        (console))
868 {
869   Lisp_Object result;
870
871   XSETCONSOLE (console, decode_console (console));
872   /* Just in case the machinations in delete_frame_internal() resulted
873      in the last-nonminibuf-frame getting out of sync, make sure and
874      return the selected frame if it's acceptable. */
875   result = Fselected_frame (CONSOLE_SELECTED_DEVICE (XCONSOLE (console)));
876   if (!NILP (result) && !FRAME_MINIBUF_ONLY_P (XFRAME (result)))
877     return result;
878   return CONSOLE_LAST_NONMINIBUF_FRAME (XCONSOLE (console));
879 }
880
881 DEFUN ("frame-root-window", Fframe_root_window, 0, 1, 0, /*
882 Return the root-window of FRAME.
883 If omitted, FRAME defaults to the currently selected frame.
884 */
885        (frame))
886 {
887   struct frame *f = decode_frame (frame);
888   return FRAME_ROOT_WINDOW (f);
889 }
890
891 DEFUN ("frame-selected-window", Fframe_selected_window, 0, 1, 0, /*
892 Return the selected window of frame object FRAME.
893 If omitted, FRAME defaults to the currently selected frame.
894 */
895        (frame))
896 {
897   struct frame *f = decode_frame (frame);
898   return FRAME_SELECTED_WINDOW (f);
899 }
900
901 void
902 set_frame_selected_window (struct frame *f, Lisp_Object window)
903 {
904   assert (XFRAME (WINDOW_FRAME (XWINDOW (window))) == f);
905   f->selected_window = window;
906   if (!MINI_WINDOW_P (XWINDOW (window)) || FRAME_MINIBUF_ONLY_P (f))
907     {
908 #ifdef HAVE_TOOLBARS
909       if (!EQ (f->last_nonminibuf_window, window))
910         {
911           MARK_TOOLBAR_CHANGED;
912           MARK_GUTTER_CHANGED;
913         }
914 #endif
915       f->last_nonminibuf_window = window;
916     }
917 }
918
919 DEFUN ("set-frame-selected-window", Fset_frame_selected_window, 2, 2, 0, /*
920 Set the selected window of frame object FRAME to WINDOW.
921 If FRAME is nil, the selected frame is used.
922 If FRAME is the selected frame, this makes WINDOW the selected window.
923 */
924        (frame, window))
925 {
926   XSETFRAME (frame, decode_frame (frame));
927   CHECK_LIVE_WINDOW (window);
928
929   if (! EQ (frame, WINDOW_FRAME (XWINDOW (window))))
930     error ("In `set-frame-selected-window', WINDOW is not on FRAME");
931
932   if (XFRAME (frame) == selected_frame ())
933     return Fselect_window (window, Qnil);
934
935   set_frame_selected_window (XFRAME (frame), window);
936   return window;
937 }
938
939 \f
940 DEFUN ("frame-device", Fframe_device, 0, 1, 0, /*
941 Return the device that FRAME is on.
942 If omitted, FRAME defaults to the currently selected frame.
943 */
944        (frame))
945 {
946   return FRAME_DEVICE (decode_frame (frame));
947 }
948
949 int
950 is_surrogate_for_selected_frame (struct frame *f)
951 {
952   struct device *d = XDEVICE (f->device);
953   struct frame *dsf = device_selected_frame (d);
954
955   /* Can't be a surrogate for ourselves. */
956   if (f == dsf)
957     return 0;
958
959   if (!FRAME_HAS_MINIBUF_P (dsf) &&
960       f == XFRAME (WINDOW_FRAME (XWINDOW (FRAME_MINIBUF_WINDOW (dsf)))))
961     return 1;
962   else
963     return 0;
964 }
965
966 static int
967 frame_matches_frametype (Lisp_Object frame, Lisp_Object type)
968 {
969   struct frame *f = XFRAME (frame);
970
971   if (WINDOWP (type))
972     {
973       CHECK_LIVE_WINDOW (type);
974
975       if (EQ (FRAME_MINIBUF_WINDOW (f), type)
976           /* Check that F either is, or has forwarded
977              its focus to, TYPE's frame.  */
978           && (EQ (WINDOW_FRAME (XWINDOW (type)), frame)
979               || EQ (WINDOW_FRAME (XWINDOW (type)),
980                      FRAME_FOCUS_FRAME (f))))
981         return 1;
982       else
983         return 0;
984     }
985
986 #if 0 /* FSFmacs */
987   if (EQ (type, Qvisible) || EQ (type, Qiconic) || EQ (type, Qvisible_iconic)
988       || EQ (type, Qvisible_nomini) || EQ (type, Qiconic_nomini)
989       || EQ (type, Qvisible_iconic_nomini))
990     FRAME_SAMPLE_VISIBILITY (f);
991 #endif
992
993   if (NILP (type))
994     type = Qnomini;
995   if (ZEROP (type))
996     type = Qvisible_iconic;
997
998   if (EQ (type, Qvisible))
999     return FRAME_VISIBLE_P (f);
1000   if (EQ (type, Qiconic))
1001     return FRAME_ICONIFIED_P (f);
1002   if (EQ (type, Qinvisible))
1003     return !FRAME_VISIBLE_P (f) && !FRAME_ICONIFIED_P (f);
1004   if (EQ (type, Qvisible_iconic))
1005     return FRAME_VISIBLE_P (f) || FRAME_ICONIFIED_P (f);
1006   if (EQ (type, Qinvisible_iconic))
1007     return !FRAME_VISIBLE_P (f);
1008
1009   if (EQ (type, Qnomini))
1010     return !FRAME_MINIBUF_ONLY_P (f);
1011   if (EQ (type, Qvisible_nomini))
1012     return FRAME_VISIBLE_P (f) && !FRAME_MINIBUF_ONLY_P (f);
1013   if (EQ (type, Qiconic_nomini))
1014     return FRAME_ICONIFIED_P (f) && !FRAME_MINIBUF_ONLY_P (f);
1015   if (EQ (type, Qinvisible_nomini))
1016     return !FRAME_VISIBLE_P (f) && !FRAME_ICONIFIED_P (f) &&
1017       !FRAME_MINIBUF_ONLY_P (f);
1018   if (EQ (type, Qvisible_iconic_nomini))
1019     return ((FRAME_VISIBLE_P (f) || FRAME_ICONIFIED_P (f))
1020             && !FRAME_MINIBUF_ONLY_P (f));
1021   if (EQ (type, Qinvisible_iconic_nomini))
1022     return !FRAME_VISIBLE_P (f) && !FRAME_MINIBUF_ONLY_P (f);
1023
1024   return 1;
1025 }
1026
1027 int
1028 device_matches_console_spec (Lisp_Object frame, Lisp_Object device,
1029                              Lisp_Object console)
1030 {
1031   if (EQ (console, Qwindow_system))
1032     return DEVICE_WIN_P (XDEVICE (device));
1033   if (NILP (console))
1034     console = (DEVICE_CONSOLE (XDEVICE (FRAME_DEVICE (XFRAME (frame)))));
1035   if (DEVICEP (console))
1036     return EQ (device, console);
1037   if (CONSOLEP (console))
1038     return EQ (DEVICE_CONSOLE (XDEVICE (device)), console);
1039   if (valid_console_type_p (console))
1040     return EQ (DEVICE_TYPE (XDEVICE (device)), console);
1041   return 1;
1042 }
1043
1044 /* Return the next frame in the frame list after FRAME.
1045    FRAMETYPE and CONSOLE control which frames and devices
1046    are considered; see `next-frame'. */
1047
1048 static Lisp_Object
1049 next_frame_internal (Lisp_Object frame, Lisp_Object frametype,
1050                      Lisp_Object console, int called_from_delete_device)
1051 {
1052   int passed = 0;
1053   int started_over = 0;
1054
1055   /* If this frame is dead, it won't be in frame_list, and we'll loop
1056      forever.  Forestall that.  */
1057   CHECK_LIVE_FRAME (frame);
1058
1059   while (1)
1060     {
1061       Lisp_Object devcons, concons;
1062
1063       DEVICE_LOOP_NO_BREAK (devcons, concons)
1064         {
1065           Lisp_Object device = XCAR (devcons);
1066           Lisp_Object frmcons;
1067
1068           if (!device_matches_console_spec (frame, device, console))
1069             continue;
1070
1071           DEVICE_FRAME_LOOP (frmcons, XDEVICE (device))
1072             {
1073               Lisp_Object f = XCAR (frmcons);
1074               if (passed)
1075                 {
1076                   /* #### Doing this here is bad and is now
1077                      unnecessary.  The real bug was that f->iconified
1078                      was never, ever updated unless a user explicitly
1079                      called frame-iconified-p.  That has now been
1080                      fixed.  With this change removed all of the other
1081                      changes made to support this routine having the
1082                      called_from_delete_device arg could be removed.
1083                      But it is too close to release to do that now. */
1084 #if 0
1085                   /* Make sure the visibility and iconified flags are
1086                      up-to-date unless we're being deleted. */
1087                   if (!called_from_delete_device)
1088                     {
1089                       Fframe_iconified_p (f);
1090                       Fframe_visible_p (f);
1091                     }
1092 #endif
1093
1094                   /* Decide whether this frame is eligible to be returned.  */
1095
1096                   /* If we've looped all the way around without finding any
1097                      eligible frames, return the original frame.  */
1098                   if (EQ (f, frame))
1099                     return f;
1100
1101                   if (frame_matches_frametype (f, frametype))
1102                     return f;
1103                 }
1104
1105               if (EQ (frame, f))
1106                 passed++;
1107             }
1108         }
1109       /* We hit the end of the list, and need to start over again. */
1110       if (started_over)
1111         return Qnil;
1112       started_over++;
1113     }
1114 }
1115
1116 Lisp_Object
1117 next_frame (Lisp_Object frame, Lisp_Object frametype, Lisp_Object console)
1118 {
1119   return next_frame_internal (frame, frametype, console, 0);
1120 }
1121
1122 /* Return the previous frame in the frame list before FRAME.
1123    FRAMETYPE and CONSOLE control which frames and devices
1124    are considered; see `next-frame'. */
1125
1126 Lisp_Object
1127 prev_frame (Lisp_Object frame, Lisp_Object frametype, Lisp_Object console)
1128 {
1129   Lisp_Object devcons, concons;
1130   Lisp_Object prev;
1131
1132   /* If this frame is dead, it won't be in frame_list, and we'll loop
1133      forever.  Forestall that.  */
1134   CHECK_LIVE_FRAME (frame);
1135
1136   prev = Qnil;
1137   DEVICE_LOOP_NO_BREAK (devcons, concons)
1138     {
1139       Lisp_Object device = XCAR (devcons);
1140       Lisp_Object frmcons;
1141
1142       if (!device_matches_console_spec (frame, device, console))
1143         continue;
1144
1145       DEVICE_FRAME_LOOP (frmcons, XDEVICE (device))
1146         {
1147           Lisp_Object f = XCAR (frmcons);
1148
1149           if (EQ (frame, f) && !NILP (prev))
1150             return prev;
1151
1152           /* Decide whether this frame is eligible to be returned,
1153              according to frametype.  */
1154
1155           if (frame_matches_frametype (f, frametype))
1156             prev = f;
1157
1158         }
1159     }
1160
1161   /* We've scanned the entire list.  */
1162   if (NILP (prev))
1163     /* We went through the whole frame list without finding a single
1164        acceptable frame.  Return the original frame.  */
1165     return frame;
1166   else
1167     /* There were no acceptable frames in the list before FRAME; otherwise,
1168        we would have returned directly from the loop.  Since PREV is the last
1169        acceptable frame in the list, return it.  */
1170     return prev;
1171 }
1172
1173 DEFUN ("next-frame", Fnext_frame, 0, 3, 0, /*
1174 Return the next frame of the right type in the frame list after FRAME.
1175 FRAMETYPE controls which frames are eligible to be returned; all
1176 others will be skipped.  Note that if there is only one eligible
1177 frame, then `next-frame' called repeatedly will always return
1178 the same frame, and if there is no eligible frame, then FRAME is
1179 returned.
1180
1181 Possible values for FRAMETYPE are
1182
1183 'visible                 Consider only frames that are visible.
1184 'iconic                  Consider only frames that are iconic.
1185 'invisible               Consider only frames that are invisible
1186                          (this is different from iconic).
1187 'visible-iconic          Consider frames that are visible or iconic.
1188 'invisible-iconic        Consider frames that are invisible or iconic.
1189 'nomini                  Consider all frames except minibuffer-only ones.
1190 'visible-nomini          Like `visible' but omits minibuffer-only frames.
1191 'iconic-nomini           Like `iconic' but omits minibuffer-only frames.
1192 'invisible-nomini        Like `invisible' but omits minibuffer-only frames.
1193 'visible-iconic-nomini   Like `visible-iconic' but omits minibuffer-only
1194                          frames.
1195 'invisible-iconic-nomini Like `invisible-iconic' but omits minibuffer-only
1196                          frames.
1197 any other value          Consider all frames.
1198
1199 If FRAMETYPE is omitted, 'nomini is used.  A FRAMETYPE of 0 (a number)
1200 is treated like 'iconic, for backwards compatibility.
1201
1202 If FRAMETYPE is a window, include only its own frame and any frame now
1203 using that window as the minibuffer.
1204
1205 Optional third argument CONSOLE controls which consoles or devices the
1206 returned frame may be on.  If CONSOLE is a console, return frames only
1207 on that console.  If CONSOLE is a device, return frames only on that
1208 device.  If CONSOLE is a console type, return frames only on consoles
1209 of that type.  If CONSOLE is 'window-system, return any frames on any
1210 window-system consoles.  If CONSOLE is nil or omitted, return frames only
1211 on the FRAME's console.  Otherwise, all frames are considered.
1212 */
1213        (frame, frametype, console))
1214 {
1215   XSETFRAME (frame, decode_frame (frame));
1216
1217   return next_frame (frame, frametype, console);
1218 }
1219
1220 DEFUN ("previous-frame", Fprevious_frame, 0, 3, 0, /*
1221 Return the next frame of the right type in the frame list after FRAME.
1222 FRAMETYPE controls which frames are eligible to be returned; all
1223 others will be skipped.  Note that if there is only one eligible
1224 frame, then `previous-frame' called repeatedly will always return
1225 the same frame, and if there is no eligible frame, then FRAME is
1226 returned.
1227
1228 See `next-frame' for an explanation of the FRAMETYPE and CONSOLE
1229 arguments.
1230 */
1231        (frame, frametype, console))
1232 {
1233   XSETFRAME (frame, decode_frame (frame));
1234
1235   return prev_frame (frame, frametype, console);
1236 }
1237
1238 /* Return any frame for which PREDICATE is non-zero, or return Qnil
1239    if there aren't any. */
1240
1241 Lisp_Object
1242 find_some_frame (int (*predicate) (Lisp_Object, void *),
1243                  void *closure)
1244 {
1245   Lisp_Object framecons, devcons, concons;
1246
1247   FRAME_LOOP_NO_BREAK (framecons, devcons, concons)
1248     {
1249       Lisp_Object frame = XCAR (framecons);
1250
1251       if ((predicate) (frame, closure))
1252         return frame;
1253     }
1254
1255   return Qnil;
1256 }
1257
1258 \f
1259
1260 /* extern void free_line_insertion_deletion_costs (struct frame *f); */
1261
1262 /* Return 1 if it is ok to delete frame F;
1263    0 if all frames aside from F are invisible.
1264    (Exception: if F is a stream frame, it's OK to delete if
1265    any other frames exist.) */
1266
1267 static int
1268 other_visible_frames_internal (struct frame *f, int called_from_delete_device)
1269 {
1270   Lisp_Object frame;
1271
1272   XSETFRAME (frame, f);
1273   if (FRAME_STREAM_P (f))
1274     return !EQ (frame, next_frame_internal (frame, Qt, Qt,
1275                                             called_from_delete_device));
1276   return !EQ (frame, next_frame_internal (frame, Qvisible_iconic_nomini, Qt,
1277                                           called_from_delete_device));
1278 }
1279
1280 int
1281 other_visible_frames (struct frame *f)
1282 {
1283   return other_visible_frames_internal (f, 0);
1284 }
1285
1286 /* Delete frame F.
1287
1288    If FORCE is non-zero, allow deletion of the only frame.
1289
1290    If CALLED_FROM_DELETE_DEVICE is non-zero, then, if
1291    deleting the last frame on a device, just delete it,
1292    instead of calling `delete-device'.
1293
1294    If FROM_IO_ERROR is non-zero, then the frame is gone due
1295    to an I/O error.  This affects what happens if we exit
1296    (we do an emergency exit instead of `save-buffers-kill-emacs'.)
1297 */
1298
1299 void
1300 delete_frame_internal (struct frame *f, int force,
1301                        int called_from_delete_device,
1302                        int from_io_error)
1303 {
1304   /* This function can GC */
1305   int minibuffer_selected;
1306   struct device *d;
1307   struct console *con;
1308   Lisp_Object frame;
1309   Lisp_Object device;
1310   Lisp_Object console;
1311   struct gcpro gcpro1;
1312
1313   /* OK to delete an already deleted frame. */
1314   if (! FRAME_LIVE_P (f))
1315     return;
1316
1317   XSETFRAME (frame, f);
1318   GCPRO1 (frame);
1319
1320   device = FRAME_DEVICE (f);
1321   d = XDEVICE (device);
1322   console = DEVICE_CONSOLE (d);
1323   con = XCONSOLE (console);
1324
1325   if (!called_from_delete_device &&
1326       !(MAYBE_INT_DEVMETH (d, device_implementation_flags, ())
1327         & XDEVIMPF_FRAMELESS_OK))
1328     {
1329       /* If we're deleting the only non-minibuffer frame on the
1330          device, delete the device. */
1331       if (EQ (frame, next_frame (frame, Qnomini, FRAME_DEVICE (f))))
1332         {
1333           delete_device_internal (d, force, 0, from_io_error);
1334           UNGCPRO;
1335           return;
1336         }
1337     }
1338
1339   /* In FSF, delete-frame will not normally allow you to delete the
1340      last visible frame.  This was too annoying, so we changed it to the
1341      only frame.  However, this would let people shoot themselves by
1342      deleting all frames which were either visible or iconified and thus
1343      losing any way of communicating with the still running XEmacs process.
1344      So we put it back.  */
1345   if (!force && !allow_deletion_of_last_visible_frame &&
1346       !other_visible_frames_internal (f, called_from_delete_device))
1347     error ("Attempt to delete the sole visible or iconified frame");
1348
1349   /* Does this frame have a minibuffer, and is it the surrogate
1350      minibuffer for any other frame?  */
1351   if (FRAME_HAS_MINIBUF_P (f))
1352     {
1353       Lisp_Object frmcons, devcons, concons;
1354
1355       FRAME_LOOP_NO_BREAK (frmcons, devcons, concons)
1356         {
1357           Lisp_Object this = XCAR (frmcons);
1358
1359           if (! EQ (this, frame)
1360               && EQ (frame, (WINDOW_FRAME
1361                              (XWINDOW
1362                               (FRAME_MINIBUF_WINDOW (XFRAME (this)))))))
1363             {
1364               /* We've found another frame whose minibuffer is on
1365                  this frame. */
1366               signal_simple_error
1367                 ("Attempt to delete a surrogate minibuffer frame", frame);
1368             }
1369         }
1370     }
1371
1372   /* Test for popup frames hanging around. */
1373   /* Deletion of a parent frame with popups is deadly. */
1374   {
1375     Lisp_Object frmcons, devcons, concons;
1376
1377     FRAME_LOOP_NO_BREAK (frmcons, devcons, concons)
1378       {
1379         Lisp_Object this = XCAR (frmcons);
1380
1381
1382         if (! EQ (this, frame))
1383           {
1384             struct device *devcons_d = XDEVICE (XCAR (devcons));
1385             if (EQ (frame, DEVMETH_OR_GIVEN (devcons_d, get_frame_parent,
1386                                              (XFRAME (this)),
1387                                              Qnil)))
1388               /* We've found a popup frame whose parent is this frame. */
1389               signal_simple_error
1390                 ("Attempt to delete a frame with live popups", frame);
1391           }
1392       }
1393   }
1394
1395   /* Before here, we haven't made any dangerous changes (just checked for
1396      error conditions).  Now run the delete-frame-hook.  Remember that
1397      user code there could do any number of dangerous things, including
1398      signalling an error. */
1399
1400   va_run_hook_with_args (Qdelete_frame_hook, 1, frame);
1401
1402   if (!FRAME_LIVE_P (f)) /* Make sure the delete-frame-hook didn't */
1403     {                    /* go ahead and delete anything. */
1404       UNGCPRO;
1405       return;
1406     }
1407
1408   /* Call the delete-device-hook and delete-console-hook now if
1409      appropriate, before we do any dangerous things -- they too could
1410      signal an error. */
1411   if (XINT (Flength (DEVICE_FRAME_LIST (d))) == 1)
1412     {
1413       va_run_hook_with_args (Qdelete_device_hook, 1, device);
1414       if (!FRAME_LIVE_P (f)) /* Make sure the delete-device-hook didn't */
1415         {                    /* go ahead and delete anything. */
1416           UNGCPRO;
1417           return;
1418         }
1419
1420       if (XINT (Flength (CONSOLE_DEVICE_LIST (con))) == 1)
1421         {
1422           va_run_hook_with_args (Qdelete_console_hook, 1, console);
1423           if (!FRAME_LIVE_P (f)) /* Make sure the delete-console-hook didn't */
1424             {                    /* go ahead and delete anything. */
1425               UNGCPRO;
1426               return;
1427             }
1428         }
1429     }
1430
1431   minibuffer_selected = EQ (minibuf_window, Fselected_window (Qnil));
1432
1433   /* If we were focused on this frame, then we're not any more.
1434      Assume that we lost the focus; that way, the call to
1435      Fselect_frame() below won't end up making us explicitly
1436      focus on another frame, which is generally undesirable in
1437      a point-to-type world.  If our mouse ends up sitting over
1438      another frame, we will receive a FocusIn event and end up
1439      making that frame the selected frame.
1440
1441      #### This may not be an ideal solution in a click-to-type
1442      world (in that case, we might want to explicitly choose
1443      another frame to have the focus, rather than relying on
1444      the WM, which might focus on a frame in a different app
1445      or focus on nothing at all).  But there's no easy way
1446      to detect which focus model we're running on, and the
1447      alternative is more heinous. */
1448
1449   if (EQ (frame, DEVICE_FRAME_WITH_FOCUS_REAL (d)))
1450     DEVICE_FRAME_WITH_FOCUS_REAL (d) = Qnil;
1451   if (EQ (frame, DEVICE_FRAME_WITH_FOCUS_FOR_HOOKS (d)))
1452     DEVICE_FRAME_WITH_FOCUS_FOR_HOOKS (d) = Qnil;
1453   if (EQ (frame, DEVICE_FRAME_THAT_OUGHT_TO_HAVE_FOCUS (d)))
1454     DEVICE_FRAME_THAT_OUGHT_TO_HAVE_FOCUS (d) = Qnil;
1455
1456   /* Don't allow the deleted frame to remain selected.
1457      Note that in the former scheme of things, this would
1458      have caused us to regain the focus.  This no longer
1459      applies (see above); I think the new behavior is more
1460      logical.  If someone disagrees, it can always be
1461      changed (or a new user variable can be introduced, ugh.) */
1462   if (EQ (frame, DEVICE_SELECTED_FRAME (d)))
1463     {
1464       Lisp_Object next;
1465
1466       /* If this is a popup frame, select its parent if possible.
1467          Otherwise, find another visible frame; if none, just take any frame.
1468          First try the same device, then the same console. */
1469
1470       next = DEVMETH_OR_GIVEN (d, get_frame_parent, (f), Qnil);
1471       if (NILP (next) || EQ (next, frame) || ! FRAME_LIVE_P (XFRAME (next)))
1472         next = next_frame_internal (frame, Qvisible, device,
1473                                     called_from_delete_device);
1474       if (NILP (next) || EQ (next, frame))
1475         next = next_frame_internal (frame, Qvisible, console,
1476                                     called_from_delete_device);
1477       if (NILP (next) || EQ (next, frame))
1478         next = next_frame_internal (frame, Qvisible, Qt,
1479                                     called_from_delete_device);
1480       if (NILP (next) || EQ (next, frame))
1481         next = next_frame_internal (frame, Qt, device,
1482                                     called_from_delete_device);
1483       if (NILP (next) || EQ (next, frame))
1484         next = next_frame_internal (frame, Qt, console,
1485                                     called_from_delete_device);
1486       if (NILP (next) || EQ (next, frame))
1487         next = next_frame_internal (frame, Qt, Qt, called_from_delete_device);
1488
1489       /* if we haven't found another frame at this point
1490          then there aren't any. */
1491       if (NILP (next) || EQ (next, frame))
1492         ;
1493       else
1494         {
1495           int did_select = 0;
1496           /* if this is the global selected frame, select another one. */
1497           if (EQ (frame, Fselected_frame (Qnil)))
1498             {
1499                 Fselect_frame (next);
1500                 did_select = 1;
1501             }
1502           /*
1503            * If the new frame we just selected is on a different
1504            * device then we still need to change DEVICE_SELECTED_FRAME(d)
1505            * to a live frame, if there are any left on this device.
1506            */
1507           if (!EQ (device, FRAME_DEVICE(XFRAME(next))))
1508             {
1509                 Lisp_Object next_f =
1510                     next_frame_internal (frame, Qt, device,
1511                                          called_from_delete_device);
1512                 if (NILP (next_f) || EQ (next_f, frame))
1513                   set_device_selected_frame (d, Qnil);
1514                 else
1515                   set_device_selected_frame (d, next_f);
1516             }
1517           else if (! did_select)
1518             set_device_selected_frame (d, next);
1519
1520         }
1521     }
1522
1523   /* Don't allow minibuf_window to remain on a deleted frame.  */
1524   if (EQ (f->minibuffer_window, minibuf_window))
1525     {
1526       struct frame *sel_frame = selected_frame ();
1527       Fset_window_buffer (sel_frame->minibuffer_window,
1528                           XWINDOW (minibuf_window)->buffer, Qt);
1529       minibuf_window = sel_frame->minibuffer_window;
1530
1531       /* If the dying minibuffer window was selected,
1532          select the new one.  */
1533       if (minibuffer_selected)
1534         Fselect_window (minibuf_window, Qnil);
1535     }
1536
1537   /* After this point, no errors must be allowed to occur. */
1538
1539 #ifdef HAVE_MENUBARS
1540   free_frame_menubars (f);
1541 #endif
1542 #ifdef HAVE_SCROLLBARS
1543   free_frame_scrollbars (f);
1544 #endif
1545 #ifdef HAVE_TOOLBARS
1546   free_frame_toolbars (f);
1547 #endif
1548   free_frame_gutters (f);
1549
1550   /* This must be done before the window and window_mirror structures
1551      are freed.  The scrollbar information is attached to them. */
1552   MAYBE_FRAMEMETH (f, delete_frame, (f));
1553
1554   /* Mark all the windows that used to be on FRAME as deleted, and then
1555      remove the reference to them.  */
1556   delete_all_subwindows (XWINDOW (f->root_window));
1557   f->root_window = Qnil;
1558
1559   /* clear out the cached glyph information */
1560   if (f->subwindow_cachels)
1561     {
1562       Dynarr_free (f->subwindow_cachels);
1563       f->subwindow_cachels = 0;
1564     }
1565
1566   /* Remove the frame now from the list.  This way, any events generated
1567      on this frame by the maneuvers below will disperse themselves. */
1568
1569   /* This used to be Fdelq(), but that will cause a seg fault if the
1570      QUIT checker happens to get invoked, because the frame list is in
1571      an inconsistent state. */
1572   d->frame_list = delq_no_quit (frame, d->frame_list);
1573   RESET_CHANGED_SET_FLAGS;
1574
1575   f->dead = 1;
1576   f->visible = 0;
1577
1578   free_window_mirror (f->root_mirror);
1579 /*  free_line_insertion_deletion_costs (f); */
1580
1581   /* If we've deleted the last non-minibuf frame, then try to find
1582      another one.  */
1583   if (EQ (frame, CONSOLE_LAST_NONMINIBUF_FRAME (con)))
1584     {
1585       Lisp_Object frmcons, devcons;
1586
1587       set_console_last_nonminibuf_frame (con, Qnil);
1588
1589       CONSOLE_FRAME_LOOP_NO_BREAK (frmcons, devcons, con)
1590         {
1591           Lisp_Object ecran = XCAR (frmcons);
1592           if (!FRAME_MINIBUF_ONLY_P (XFRAME (ecran)))
1593             {
1594               set_console_last_nonminibuf_frame (con, ecran);
1595               goto double_break_1;
1596             }
1597         }
1598     }
1599  double_break_1:
1600
1601 #if 0
1602   /* The following test is degenerate FALSE */
1603   if (called_from_delete_device < 0)
1604     /* then we're being called from delete-console, and we shouldn't
1605        try to find another default-minibuffer frame for the console.
1606        */
1607     con->default_minibuffer_frame = Qnil;
1608 #endif
1609
1610   /* If we've deleted this console's default_minibuffer_frame, try to
1611      find another one.  Prefer minibuffer-only frames, but also notice
1612      frames with other windows.  */
1613   if (EQ (frame, con->default_minibuffer_frame))
1614     {
1615       Lisp_Object frmcons, devcons;
1616       /* The last frame we saw with a minibuffer, minibuffer-only or not.  */
1617       Lisp_Object frame_with_minibuf;
1618       /* Some frame we found on the same console, or nil if there are none. */
1619       Lisp_Object frame_on_same_console;
1620
1621       frame_on_same_console = Qnil;
1622       frame_with_minibuf = Qnil;
1623
1624       set_console_last_nonminibuf_frame (con, Qnil);
1625
1626       CONSOLE_FRAME_LOOP_NO_BREAK (frmcons, devcons, con)
1627         {
1628           Lisp_Object this;
1629           struct frame *f1;
1630
1631           this = XCAR (frmcons);
1632           f1 = XFRAME (this);
1633
1634           /* Consider only frames on the same console
1635              and only those with minibuffers.  */
1636           if (FRAME_HAS_MINIBUF_P (f1))
1637             {
1638               frame_with_minibuf = this;
1639               if (FRAME_MINIBUF_ONLY_P (f1))
1640                 goto double_break_2;
1641             }
1642
1643           frame_on_same_console = this;
1644         }
1645     double_break_2:
1646
1647       if (!NILP (frame_on_same_console))
1648         {
1649           /* We know that there must be some frame with a minibuffer out
1650              there.  If this were not true, all of the frames present
1651              would have to be minibuffer-less, which implies that at some
1652              point their minibuffer frames must have been deleted, but
1653              that is prohibited at the top; you can't delete surrogate
1654              minibuffer frames.  */
1655           if (NILP (frame_with_minibuf))
1656             abort ();
1657
1658           con->default_minibuffer_frame = frame_with_minibuf;
1659         }
1660       else
1661         /* No frames left on this console--say no minibuffer either.  */
1662         con->default_minibuffer_frame = Qnil;
1663     }
1664
1665   nuke_all_frame_slots (f); /* nobody should be accessing the device
1666                                or anything else any more, and making
1667                                them Qnil allows for better GC'ing
1668                                in case a pointer to the dead frame
1669                                continues to hang around. */
1670   f->framemeths = dead_console_methods;
1671   UNGCPRO;
1672 }
1673
1674 void
1675 io_error_delete_frame (Lisp_Object frame)
1676 {
1677   delete_frame_internal (XFRAME (frame), 1, 0, 1);
1678 }
1679
1680 DEFUN ("delete-frame", Fdelete_frame, 0, 2, "", /*
1681 Delete FRAME, permanently eliminating it from use.
1682 If omitted, FRAME defaults to the selected frame.
1683 A frame may not be deleted if its minibuffer is used by other frames.
1684 Normally, you cannot delete the last non-minibuffer-only frame (you must
1685 use `save-buffers-kill-emacs' or `kill-emacs').  However, if optional
1686 second argument FORCE is non-nil, you can delete the last frame. (This
1687 will automatically call `save-buffers-kill-emacs'.)
1688 */
1689        (frame, force))
1690 {
1691   /* This function can GC */
1692   struct frame *f;
1693
1694   if (NILP (frame))
1695     {
1696       f = selected_frame ();
1697       XSETFRAME (frame, f);
1698     }
1699   else
1700     {
1701       CHECK_FRAME (frame);
1702       f = XFRAME (frame);
1703     }
1704
1705   delete_frame_internal (f, !NILP (force), 0, 0);
1706   return Qnil;
1707 }
1708
1709 \f
1710 /* Return mouse position in character cell units.  */
1711
1712 static int
1713 mouse_pixel_position_1 (struct device *d, Lisp_Object *frame,
1714                         int *x, int *y)
1715 {
1716   switch (DEVMETH_OR_GIVEN (d, get_mouse_position, (d, frame, x, y), -1))
1717     {
1718     case 1:
1719       return 1;
1720
1721     case 0:
1722       *frame = Qnil;
1723       break;
1724
1725     case -1:
1726       *frame = DEVICE_SELECTED_FRAME (d);
1727       break;
1728
1729     default:
1730       abort (); /* method is incorrectly written */
1731     }
1732
1733   return 0;
1734 }
1735
1736 DEFUN ("mouse-pixel-position", Fmouse_pixel_position, 0, 1, 0, /*
1737 Return a list (WINDOW X . Y) giving the current mouse window and position.
1738 The position is given in pixel units, where (0, 0) is the upper-left corner.
1739
1740 When the cursor is not over a window, the return value is a list (nil nil).
1741
1742 DEVICE specifies the device on which to read the mouse position, and
1743 defaults to the selected device.  If the device is a mouseless terminal
1744 or Emacs hasn't been programmed to read its mouse position, it returns
1745 the device's selected window for WINDOW and nil for X and Y.
1746 */
1747        (device))
1748 {
1749   struct device *d = decode_device (device);
1750   Lisp_Object frame;
1751   Lisp_Object window = Qnil;
1752   Lisp_Object x = Qnil;
1753   Lisp_Object y = Qnil;
1754   int intx, inty;
1755
1756   if (mouse_pixel_position_1 (d, &frame, &intx, &inty) > 0)
1757     {
1758       struct window *w =
1759         find_window_by_pixel_pos (intx, inty, XFRAME (frame)->root_window);
1760       if (w)
1761         {
1762           XSETWINDOW (window, w);
1763
1764           /* Adjust the position to be relative to the window. */
1765           intx -= w->pixel_left;
1766           inty -= w->pixel_top;
1767           XSETINT (x, intx);
1768           XSETINT (y, inty);
1769         }
1770     }
1771   else if (FRAMEP (frame))
1772     window = FRAME_SELECTED_WINDOW (XFRAME (frame));
1773
1774   return Fcons (window, Fcons (x, y));
1775 }
1776
1777 DEFUN ("mouse-position", Fmouse_position, 0, 1, 0, /*
1778 Return a list (WINDOW X . Y) giving the current mouse window and position.
1779 The position is of a character under cursor, where (0, 0) is the upper-left
1780 corner of the window.
1781
1782 When the cursor is not over a character, or not over a window, the return
1783 value is a list (nil nil).
1784
1785 DEVICE specifies the device on which to read the mouse position, and
1786 defaults to the selected device.  If the device is a mouseless terminal
1787 or Emacs hasn't been programmed to read its mouse position, it returns
1788 the device's selected window for WINDOW and nil for X and Y.
1789 */
1790        (device))
1791 {
1792   struct device *d = decode_device (device);
1793   struct window *w;
1794   Lisp_Object frame, window = Qnil, lisp_x = Qnil, lisp_y = Qnil;
1795   int x, y, obj_x, obj_y;
1796   Bufpos bufpos, closest;
1797   Charcount modeline_closest;
1798   Lisp_Object obj1, obj2;
1799
1800   if (mouse_pixel_position_1 (d, &frame, &x, &y) > 0)
1801     {
1802       int res = pixel_to_glyph_translation (XFRAME (frame), x, y, &x, &y,
1803                                             &obj_x, &obj_y, &w, &bufpos,
1804                                             &closest, &modeline_closest,
1805                                             &obj1, &obj2);
1806       if (res == OVER_TEXT)
1807         {
1808           lisp_x = make_int (x);
1809           lisp_y = make_int (y);
1810           XSETWINDOW (window, w);
1811         }
1812     }
1813   else if (FRAMEP (frame))
1814     window = FRAME_SELECTED_WINDOW (XFRAME (frame));
1815
1816   return Fcons (window, Fcons (lisp_x, lisp_y));
1817 }
1818
1819 DEFUN ("mouse-position-as-motion-event", Fmouse_position_as_motion_event, 0, 1, 0, /*
1820 Return the current mouse position as a motion event.
1821 This allows you to call the standard event functions such as
1822 `event-over-toolbar-p' to determine where the mouse is.
1823
1824 DEVICE specifies the device on which to read the mouse position, and
1825 defaults to the selected device.  If the mouse position can't be determined
1826 \(e.g. DEVICE is a TTY device), nil is returned instead of an event.
1827 */
1828        (device))
1829 {
1830   struct device *d = decode_device (device);
1831   Lisp_Object frame;
1832   int intx, inty;
1833
1834   if (mouse_pixel_position_1 (d, &frame, &intx, &inty))
1835     {
1836       Lisp_Object event = Fmake_event (Qnil, Qnil);
1837       XEVENT (event)->event_type = pointer_motion_event;
1838       XEVENT (event)->channel = frame;
1839       XEVENT (event)->event.motion.x = intx;
1840       XEVENT (event)->event.motion.y = inty;
1841       return event;
1842     }
1843   else
1844     return Qnil;
1845 }
1846
1847 DEFUN ("set-mouse-position", Fset_mouse_position, 3, 3, 0, /*
1848 Move the mouse pointer to the center of character cell (X,Y) in WINDOW.
1849 Note, this is a no-op for an X frame that is not visible.
1850 If you have just created a frame, you must wait for it to become visible
1851 before calling this function on it, like this.
1852   (while (not (frame-visible-p frame)) (sleep-for .5))
1853 Note also: Warping the mouse is contrary to the ICCCM, so be very sure
1854  that the behavior won't end up being obnoxious!
1855 */
1856        (window, x, y))
1857 {
1858   struct window *w;
1859   int pix_x, pix_y;
1860
1861   CHECK_LIVE_WINDOW (window);
1862   CHECK_INT (x);
1863   CHECK_INT (y);
1864
1865   /* Warping the mouse will cause EnterNotify and Focus events under X. */
1866   w = XWINDOW (window);
1867   glyph_to_pixel_translation (w, XINT (x), XINT (y), &pix_x, &pix_y);
1868
1869   MAYBE_FRAMEMETH (XFRAME (w->frame), set_mouse_position, (w, pix_x, pix_y));
1870
1871   return Qnil;
1872 }
1873
1874 DEFUN ("set-mouse-pixel-position", Fset_mouse_pixel_position, 3, 3, 0, /*
1875 Move the mouse pointer to pixel position (X,Y) in WINDOW.
1876 Note, this is a no-op for an X frame that is not visible.
1877 If you have just created a frame, you must wait for it to become visible
1878 before calling this function on it, like this.
1879   (while (not (frame-visible-p frame)) (sleep-for .5))
1880 */
1881        (window, x, y))
1882 {
1883   struct window *w;
1884
1885   CHECK_LIVE_WINDOW (window);
1886   CHECK_INT (x);
1887   CHECK_INT (y);
1888
1889   /* Warping the mouse will cause EnterNotify and Focus events under X. */
1890   w = XWINDOW (window);
1891   FRAMEMETH (XFRAME (w->frame), set_mouse_position, (w, XINT (x), XINT (y)));
1892
1893   return Qnil;
1894 }
1895 \f
1896 DEFUN ("make-frame-visible", Fmake_frame_visible, 0, 1, 0, /*
1897 Make the frame FRAME visible (assuming it is an X-window).
1898 If omitted, FRAME defaults to the currently selected frame.
1899 Also raises the frame so that nothing obscures it.
1900 */
1901        (frame))
1902 {
1903   struct frame *f = decode_frame (frame);
1904
1905   MAYBE_FRAMEMETH (f, make_frame_visible, (f));
1906   return frame;
1907 }
1908
1909 DEFUN ("make-frame-invisible", Fmake_frame_invisible, 0, 2, 0, /*
1910 Unconditionally removes frame from the display (assuming it is an X-window).
1911 If omitted, FRAME defaults to the currently selected frame.
1912 If what you want to do is iconify the frame (if the window manager uses
1913 icons) then you should call `iconify-frame' instead.
1914 Normally you may not make FRAME invisible if all other frames are invisible
1915 and uniconified, but if the second optional argument FORCE is non-nil,
1916 you may do so.
1917 */
1918        (frame, force))
1919 {
1920   struct frame *f, *sel_frame;
1921   struct device *d;
1922
1923   f = decode_frame (frame);
1924   d = XDEVICE (FRAME_DEVICE (f));
1925   sel_frame = XFRAME (DEVICE_SELECTED_FRAME (d));
1926
1927   if (NILP (force) && !other_visible_frames (f))
1928     error ("Attempt to make invisible the sole visible or iconified frame");
1929
1930   /* Don't allow minibuf_window to remain on a deleted frame.  */
1931   if (EQ (f->minibuffer_window, minibuf_window))
1932     {
1933       Fset_window_buffer (sel_frame->minibuffer_window,
1934                           XWINDOW (minibuf_window)->buffer, Qt);
1935       minibuf_window = sel_frame->minibuffer_window;
1936     }
1937
1938   MAYBE_FRAMEMETH (f, make_frame_invisible, (f));
1939
1940   return Qnil;
1941 }
1942
1943 DEFUN ("iconify-frame", Ficonify_frame, 0, 1, "", /*
1944 Make the frame FRAME into an icon, if the window manager supports icons.
1945 If omitted, FRAME defaults to the currently selected frame.
1946 */
1947        (frame))
1948 {
1949   struct frame *f, *sel_frame;
1950   struct device *d;
1951
1952   f = decode_frame (frame);
1953   d = XDEVICE (FRAME_DEVICE (f));
1954   sel_frame = XFRAME (DEVICE_SELECTED_FRAME (d));
1955
1956   /* Don't allow minibuf_window to remain on a deleted frame.  */
1957   if (EQ (f->minibuffer_window, minibuf_window))
1958     {
1959       Fset_window_buffer (sel_frame->minibuffer_window,
1960                           XWINDOW (minibuf_window)->buffer, Qt);
1961       minibuf_window = sel_frame->minibuffer_window;
1962     }
1963
1964   MAYBE_FRAMEMETH (f, iconify_frame, (f));
1965
1966   return Qnil;
1967 }
1968
1969 DEFUN ("deiconify-frame", Fdeiconify_frame, 0, 1, 0, /*
1970 Open (de-iconify) the iconified frame FRAME.
1971 Under X, this is currently the same as `make-frame-visible'.
1972 If omitted, FRAME defaults to the currently selected frame.
1973 Also raises the frame so that nothing obscures it.
1974 */
1975        (frame))
1976 {
1977   return Fmake_frame_visible (frame);
1978 }
1979
1980 /* FSF returns 'icon for iconized frames.  What a crock! */
1981
1982 DEFUN ("frame-visible-p", Fframe_visible_p, 0, 1, 0, /*
1983 Return non NIL if FRAME is now "visible" (actually in use for display).
1984 A frame that is not visible is not updated, and, if it works through a
1985 window system, may not show at all.
1986 N.B. Under X "visible" means Mapped. It the window is mapped but not
1987 actually visible on screen then frame_visible returns 'hidden.
1988 */
1989        (frame))
1990 {
1991   struct frame *f = decode_frame (frame);
1992   int visible = FRAMEMETH_OR_GIVEN (f, frame_visible_p, (f), f->visible);
1993   return visible ? ( visible > 0 ? Qt : Qhidden ) : Qnil;
1994 }
1995
1996 DEFUN ("frame-totally-visible-p", Fframe_totally_visible_p, 0, 1, 0, /*
1997 Return t if frame is not obscured by any other window system windows.
1998 Always returns t for tty frames.
1999 */
2000        (frame))
2001 {
2002   struct frame *f = decode_frame (frame);
2003   return (FRAMEMETH_OR_GIVEN (f, frame_totally_visible_p, (f), f->visible)
2004           ? Qt : Qnil);
2005 }
2006
2007 DEFUN ("frame-iconified-p", Fframe_iconified_p, 0, 1, 0, /*
2008 Return t if FRAME is iconified.
2009 Not all window managers use icons; some merely unmap the window, so this
2010 function is not the inverse of `frame-visible-p'.  It is possible for a
2011 frame to not be visible and not be iconified either.  However, if the
2012 frame is iconified, it will not be visible.
2013 */
2014        (frame))
2015 {
2016   struct frame *f = decode_frame (frame);
2017   if (f->visible)
2018     return Qnil;
2019   f->iconified = FRAMEMETH_OR_GIVEN (f, frame_iconified_p, (f), 0);
2020   return f->iconified ? Qt : Qnil;
2021 }
2022
2023 DEFUN ("visible-frame-list", Fvisible_frame_list, 0, 1, 0, /*
2024 Return a list of all frames now "visible" (being updated).
2025 If DEVICE is specified only frames on that device will be returned.
2026 Note that under virtual window managers not all these frame are necessarily
2027 really updated.
2028 */
2029        (device))
2030 {
2031   Lisp_Object devcons, concons;
2032   struct frame *f;
2033   Lisp_Object value;
2034
2035   value = Qnil;
2036
2037   DEVICE_LOOP_NO_BREAK (devcons, concons)
2038     {
2039       assert (DEVICEP (XCAR (devcons)));
2040
2041       if (NILP (device) || EQ (device, XCAR (devcons)))
2042         {
2043           Lisp_Object frmcons;
2044
2045           DEVICE_FRAME_LOOP (frmcons, XDEVICE (XCAR (devcons)))
2046             {
2047               Lisp_Object frame = XCAR (frmcons);
2048               f = XFRAME (frame);
2049               if (FRAME_VISIBLE_P(f))
2050                 value = Fcons (frame, value);
2051             }
2052         }
2053     }
2054
2055   return value;
2056 }
2057
2058 \f
2059 DEFUN ("raise-frame", Fraise_frame, 0, 1, "", /*
2060 Bring FRAME to the front, so it occludes any frames it overlaps.
2061 If omitted, FRAME defaults to the currently selected frame.
2062 If FRAME is invisible, make it visible.
2063 If Emacs is displaying on an ordinary terminal or some other device which
2064 doesn't support multiple overlapping frames, this function does nothing.
2065 */
2066        (frame))
2067 {
2068   struct frame *f = decode_frame (frame);
2069
2070   /* Do like the documentation says. */
2071   Fmake_frame_visible (frame);
2072   MAYBE_FRAMEMETH (f, raise_frame, (f));
2073   return Qnil;
2074 }
2075
2076 DEFUN ("lower-frame", Flower_frame, 0, 1, "", /*
2077 Send FRAME to the back, so it is occluded by any frames that overlap it.
2078 If omitted, FRAME defaults to the currently selected frame.
2079 If Emacs is displaying on an ordinary terminal or some other device which
2080 doesn't support multiple overlapping frames, this function does nothing.
2081 */
2082        (frame))
2083 {
2084   struct frame *f = decode_frame (frame);
2085
2086   MAYBE_FRAMEMETH (f, lower_frame, (f));
2087   return Qnil;
2088 }
2089
2090 /* Ben thinks there is no need for `redirect-frame-focus' or `frame-focus',
2091    crockish FSFmacs functions.  See summary on focus in event-stream.c. */
2092 \f
2093 DEFUN ("print-job-page-number", Fprint_job_page_number, 1, 1, 0, /*
2094 Return current page number for the print job FRAME.
2095 */
2096        (frame))
2097 {
2098   CHECK_PRINTER_FRAME (frame);
2099   return make_int (FRAME_PAGENUMBER (XFRAME (frame)));
2100 }
2101
2102 DEFUN ("print-job-eject-page", Fprint_job_eject_page, 1, 1, 0, /*
2103 Eject page in the print job FRAME.
2104 */
2105        (frame))
2106 {
2107   struct frame *f;
2108
2109   CHECK_PRINTER_FRAME (frame);
2110   f = XFRAME (frame);
2111   FRAMEMETH (f, eject_page, (f));
2112   FRAME_SET_PAGENUMBER (f, 1 + FRAME_PAGENUMBER (f));
2113   f->clear = 1;
2114
2115   return Qnil;
2116 }
2117
2118 \f
2119 /***************************************************************************/
2120 /*                           frame properties                              */
2121 /***************************************************************************/
2122
2123 static void internal_set_frame_size (struct frame *f, int cols, int rows,
2124                                      int pretend);
2125
2126 static void
2127 store_minibuf_frame_prop (struct frame *f, Lisp_Object val)
2128 {
2129   Lisp_Object frame;
2130   XSETFRAME (frame, f);
2131
2132   if (WINDOWP (val))
2133     {
2134       if (! MINI_WINDOW_P (XWINDOW (val)))
2135         signal_simple_error
2136           ("Surrogate minibuffer windows must be minibuffer windows",
2137            val);
2138
2139       if (FRAME_HAS_MINIBUF_P (f) || FRAME_MINIBUF_ONLY_P (f))
2140         signal_simple_error
2141           ("Can't change the surrogate minibuffer of a frame with its own minibuffer", frame);
2142
2143       /* Install the chosen minibuffer window, with proper buffer.  */
2144       f->minibuffer_window = val;
2145     }
2146   else if (EQ (val, Qt))
2147     {
2148       if (FRAME_HAS_MINIBUF_P (f) || FRAME_MINIBUF_ONLY_P (f))
2149         signal_simple_error
2150           ("Frame already has its own minibuffer", frame);
2151       else
2152         {
2153           setup_normal_frame (f);
2154           f->mirror_dirty = 1;
2155
2156           update_frame_window_mirror (f);
2157           internal_set_frame_size (f, f->width, f->height, 1);
2158         }
2159     }
2160 }
2161
2162 #if 0
2163
2164 /* possible code if you want to have symbols such as `default-background'
2165    map to setting the background of `default', etc. */
2166
2167 static int
2168 dissect_as_face_setting (Lisp_Object sym, Lisp_Object *face_out,
2169                          Lisp_Object *face_prop_out)
2170 {
2171   Lisp_Object list = Vbuilt_in_face_specifiers;
2172   Lisp_String *s;
2173
2174   if (!SYMBOLP (sym))
2175     return 0;
2176
2177   s = symbol_name (XSYMBOL (sym));
2178
2179   while (!NILP (list))
2180     {
2181       Lisp_Object prop = Fcar (list);
2182       Lisp_String *prop_name;
2183
2184       if (!SYMBOLP (prop))
2185         continue;
2186       prop_name = symbol_name (XSYMBOL (prop));
2187       if (string_length (s) > string_length (prop_name) + 1
2188           && !memcmp (string_data (prop_name),
2189                       string_data (s) + string_length (s)
2190                       - string_length (prop_name),
2191                       string_length (prop_name))
2192           && string_data (s)[string_length (s) - string_length (prop_name)
2193                              - 1] == '-')
2194         {
2195           Lisp_Object face =
2196             Ffind_face (make_string (string_data (s),
2197                                      string_length (s)
2198                                      - string_length (prop_name)
2199                                      - 1));
2200           if (!NILP (face))
2201             {
2202               *face_out = face;
2203               *face_prop_out = prop;
2204               return 1;
2205             }
2206         }
2207
2208       list = Fcdr (list);
2209     }
2210
2211   return 0;
2212 }
2213
2214 #endif /* 0 */
2215
2216 static Lisp_Object
2217 get_property_alias (Lisp_Object prop)
2218 {
2219   while (1)
2220     {
2221       Lisp_Object alias = Qnil;
2222
2223       if (SYMBOLP (prop))
2224         alias = Fget (prop, Qframe_property_alias, Qnil);
2225       if (NILP (alias))
2226         break;
2227       prop = alias;
2228       QUIT;
2229     }
2230
2231   return prop;
2232 }
2233
2234 /* #### Using this to modify the internal border width has no effect
2235    because the change isn't propagated to the windows.  Are there
2236    other properties which this claims to handle, but doesn't?
2237
2238    But of course.  This stuff needs more work, but it's a lot closer
2239    to sanity now than before with the horrible frame-params stuff. */
2240
2241 DEFUN ("set-frame-properties", Fset_frame_properties, 2, 2, 0, /*
2242 Change some properties of a frame.
2243 PLIST is a property list.
2244 You can also change frame properties individually using `set-frame-property',
2245 but it may be more efficient to change many properties at once.
2246
2247 Frame properties can be retrieved using `frame-property' or `frame-properties'.
2248
2249 The following symbols etc. have predefined meanings:
2250
2251  name           Name of the frame.  Used with X resources.
2252                 Unchangeable after creation.
2253
2254  height         Height of the frame, in lines.
2255
2256  width          Width of the frame, in characters.
2257
2258  minibuffer     Gives the minibuffer behavior for this frame.  Either
2259                 t (frame has its own minibuffer), `only' (frame is
2260                 a minibuffer-only frame), or a window (frame uses that
2261                 window, which is on another frame, as the minibuffer).
2262
2263  unsplittable   If non-nil, frame cannot be split by `display-buffer'.
2264
2265  current-display-table, menubar-visible-p, left-margin-width,
2266  right-margin-width, minimum-line-ascent, minimum-line-descent,
2267  use-left-overflow, use-right-overflow, scrollbar-width, scrollbar-height,
2268  default-toolbar, top-toolbar, bottom-toolbar, left-toolbar, right-toolbar,
2269  default-toolbar-height, default-toolbar-width, top-toolbar-height,
2270  bottom-toolbar-height, left-toolbar-width, right-toolbar-width,
2271  default-toolbar-visible-p, top-toolbar-visible-p, bottom-toolbar-visible-p,
2272  left-toolbar-visible-p, right-toolbar-visible-p, toolbar-buttons-captioned-p,
2273  top-toolbar-border-width, bottom-toolbar-border-width,
2274  left-toolbar-border-width, right-toolbar-border-width,
2275  modeline-shadow-thickness, has-modeline-p
2276                 [Giving the name of any built-in specifier variable is
2277                 equivalent to calling `set-specifier' on the specifier,
2278                 with a locale of FRAME.  Giving the name to `frame-property'
2279                 calls `specifier-instance' on the specifier.]
2280
2281  text-pointer-glyph, nontext-pointer-glyph, modeline-pointer-glyph,
2282  selection-pointer-glyph, busy-pointer-glyph, toolbar-pointer-glyph,
2283  menubar-pointer-glyph, scrollbar-pointer-glyph, gc-pointer-glyph,
2284  octal-escape-glyph, control-arrow-glyph, invisible-text-glyph,
2285  hscroll-glyph, truncation-glyph, continuation-glyph
2286                 [Giving the name of any glyph variable is equivalent to
2287                 calling `set-glyph-image' on the glyph, with a locale
2288                 of FRAME.  Giving the name to `frame-property' calls
2289                 `glyph-image-instance' on the glyph.]
2290
2291  [default foreground], [default background], [default font],
2292  [modeline foreground], [modeline background], [modeline font],
2293  etc.
2294                 [Giving a vector of a face and a property is equivalent
2295                 to calling `set-face-property' on the face and property,
2296                 with a locale of FRAME.  Giving the vector to
2297                 `frame-property' calls `face-property-instance' on the
2298                 face and property.]
2299
2300 Finally, if a frame property symbol has the property `frame-property-alias'
2301 on it, then the value will be used in place of that symbol when looking
2302 up and setting frame property values.  This allows you to alias one
2303 frame property name to another.
2304
2305 See the variables `default-x-frame-plist', `default-tty-frame-plist'
2306 and `default-mswindows-frame-plist' for a description of the properties
2307 recognized for particular types of frames.
2308 */
2309        (frame, plist))
2310 {
2311   struct frame *f = decode_frame (frame);
2312   Lisp_Object tail;
2313   Lisp_Object *tailp;
2314   struct gcpro gcpro1, gcpro2;
2315
2316   XSETFRAME (frame, f);
2317   GCPRO2 (frame, plist);
2318   Fcheck_valid_plist (plist);
2319   plist = Fcopy_sequence (plist);
2320   Fcanonicalize_lax_plist (plist, Qnil);
2321   for (tail = plist; !NILP (tail); tail = Fcdr (Fcdr (tail)))
2322     {
2323       Lisp_Object prop = Fcar (tail);
2324       Lisp_Object val = Fcar (Fcdr (tail));
2325
2326       prop = get_property_alias (prop);
2327
2328 #if 0
2329       /* mly wants this, but it's not reasonable to change the name of a
2330          frame after it has been created, because the old name was used
2331          for resource lookup. */
2332       if (EQ (prop, Qname))
2333         {
2334           CHECK_STRING (val);
2335           f->name = val;
2336         }
2337 #endif /* 0 */
2338       if (EQ (prop, Qminibuffer))
2339         store_minibuf_frame_prop (f, val);
2340       if (EQ (prop, Qunsplittable))
2341         f->no_split = !NILP (val);
2342       if (EQ (prop, Qbuffer_predicate))
2343         f->buffer_predicate = val;
2344       if (SYMBOLP (prop) && EQ (Fbuilt_in_variable_type (prop),
2345                                 Qconst_specifier))
2346         call3 (Qset_specifier, Fsymbol_value (prop), val, frame);
2347       if (SYMBOLP (prop) && !NILP (Fget (prop, Qconst_glyph_variable, Qnil)))
2348         call3 (Qset_glyph_image, Fsymbol_value (prop), val, frame);
2349       if (VECTORP (prop) && XVECTOR_LENGTH (prop) == 2)
2350         {
2351           Lisp_Object face_prop = XVECTOR_DATA (prop)[1];
2352           CHECK_SYMBOL (face_prop);
2353           call4 (Qset_face_property,
2354                  Fget_face (XVECTOR_DATA (prop)[0]),
2355                  face_prop, val, frame);
2356         }
2357     }
2358
2359   MAYBE_FRAMEMETH (f, set_frame_properties, (f, plist));
2360   for (tailp = &plist; !NILP (*tailp);)
2361     {
2362       Lisp_Object *next_tailp;
2363       Lisp_Object next;
2364       Lisp_Object prop;
2365
2366       next = Fcdr (*tailp);
2367       CHECK_CONS (next);
2368       next_tailp = &XCDR (next);
2369       prop = Fcar (*tailp);
2370
2371       prop = get_property_alias (prop);
2372
2373       if (EQ (prop, Qminibuffer)
2374           || EQ (prop, Qunsplittable)
2375           || EQ (prop, Qbuffer_predicate)
2376           || EQ (prop, Qheight)
2377           || EQ (prop, Qwidth)
2378           || (SYMBOLP (prop) && EQ (Fbuilt_in_variable_type (prop),
2379                                     Qconst_specifier))
2380           || (SYMBOLP (prop) && !NILP (Fget (prop, Qconst_glyph_variable,
2381                                              Qnil)))
2382           || (VECTORP (prop) && XVECTOR_LENGTH (prop) == 2)
2383           || FRAMEMETH_OR_GIVEN (f, internal_frame_property_p, (f, prop), 0))
2384         *tailp = *next_tailp;
2385       tailp = next_tailp;
2386     }
2387
2388   f->plist = nconc2 (plist, f->plist);
2389   Fcanonicalize_lax_plist (f->plist, Qnil);
2390   UNGCPRO;
2391   return Qnil;
2392 }
2393
2394 DEFUN ("frame-property", Fframe_property, 2, 3, 0, /*
2395 Return FRAME's value for property PROPERTY.
2396 See `set-frame-properties' for the built-in property names.
2397 */
2398        (frame, property, default_))
2399 {
2400   struct frame *f = decode_frame (frame);
2401   Lisp_Object value;
2402
2403   XSETFRAME (frame, f);
2404
2405   property = get_property_alias (property);
2406
2407   if (EQ (Qname, property)) return f->name;
2408
2409   if (EQ (Qheight, property) || EQ (Qwidth, property))
2410     {
2411       if (window_system_pixelated_geometry (frame))
2412         {
2413           int width, height;
2414           pixel_to_real_char_size (f, FRAME_PIXWIDTH (f), FRAME_PIXHEIGHT (f),
2415                                    &width, &height);
2416           return make_int (EQ (Qheight, property) ? height: width);
2417         }
2418       else
2419         return make_int (EQ (Qheight, property) ?
2420                          FRAME_HEIGHT (f) :
2421                          FRAME_WIDTH  (f));
2422     }
2423
2424   /* NOTE: FSF returns Qnil instead of Qt for FRAME_HAS_MINIBUF_P.
2425      This is over-the-top bogosity, because it's inconsistent with
2426      the semantics of `minibuffer' when passed to `make-frame'.
2427      Returning Qt makes things consistent. */
2428   if (EQ (Qminibuffer, property))
2429     return (FRAME_MINIBUF_ONLY_P (f) ? Qonly :
2430             FRAME_HAS_MINIBUF_P  (f) ? Qt    :
2431             FRAME_MINIBUF_WINDOW (f));
2432   if (EQ (Qunsplittable, property))
2433     return FRAME_NO_SPLIT_P (f) ? Qt : Qnil;
2434   if (EQ (Qbuffer_predicate, property))
2435     return f->buffer_predicate;
2436
2437   if (SYMBOLP (property))
2438     {
2439       if (EQ (Fbuilt_in_variable_type (property), Qconst_specifier))
2440         return Fspecifier_instance (Fsymbol_value (property),
2441                                     frame, default_, Qnil);
2442       if (!NILP (Fget (property, Qconst_glyph_variable, Qnil)))
2443         {
2444           Lisp_Object glyph = Fsymbol_value (property);
2445           CHECK_GLYPH (glyph);
2446           return Fspecifier_instance (XGLYPH_IMAGE (glyph),
2447                                       frame, default_, Qnil);
2448         }
2449     }
2450
2451   if (VECTORP (property) && XVECTOR_LENGTH (property) == 2)
2452     {
2453       Lisp_Object face_prop = XVECTOR_DATA (property)[1];
2454       CHECK_SYMBOL (face_prop);
2455       return call3 (Qface_property_instance,
2456                     Fget_face (XVECTOR_DATA (property)[0]),
2457                     face_prop, frame);
2458     }
2459
2460   if (HAS_FRAMEMETH_P (f, frame_property))
2461     if (!UNBOUNDP (value = FRAMEMETH (f, frame_property, (f, property))))
2462       return value;
2463
2464   if (!UNBOUNDP (value = external_plist_get (&f->plist, property, 1, ERROR_ME)))
2465     return value;
2466
2467   return default_;
2468 }
2469
2470 DEFUN ("frame-properties", Fframe_properties, 0, 1, 0, /*
2471 Return a property list of the properties of FRAME.
2472 Do not modify this list; use `set-frame-property' instead.
2473 */
2474        (frame))
2475 {
2476   struct frame *f = decode_frame (frame);
2477   Lisp_Object result = Qnil;
2478   struct gcpro gcpro1;
2479
2480   GCPRO1 (result);
2481
2482   XSETFRAME (frame, f);
2483
2484   /* #### for the moment (since old code uses `frame-parameters'),
2485      we call `copy-sequence' on f->plist.  That allows frame-parameters
2486      to destructively convert the plist into an alist, which is more
2487      efficient than doing it non-destructively.  At some point we
2488      should remove the call to copy-sequence. */
2489   result = Fcopy_sequence (f->plist);
2490
2491   /* #### should we be adding all the specifiers and glyphs?
2492      That would entail having a list of them all. */
2493   if (HAS_FRAMEMETH_P (f, frame_properties))
2494     result = nconc2 (FRAMEMETH (f, frame_properties, (f)), result);
2495
2496   if (!NILP (f->buffer_predicate))
2497     result = cons3 (Qbuffer_predicate, f->buffer_predicate, result);
2498
2499   if (FRAME_NO_SPLIT_P (f))
2500     result = cons3 (Qunsplittable, Qt, result);
2501
2502   /* NOTE: FSF returns Qnil instead of Qt for FRAME_HAS_MINIBUF_P.
2503      This is over-the-top bogosity, because it's inconsistent with
2504      the semantics of `minibuffer' when passed to `make-frame'.
2505      Returning Qt makes things consistent. */
2506   result = cons3 (Qminibuffer,
2507                   (FRAME_MINIBUF_ONLY_P (f) ? Qonly :
2508                    FRAME_HAS_MINIBUF_P  (f) ? Qt    :
2509                    FRAME_MINIBUF_WINDOW (f)),
2510                   result);
2511   {
2512     int width, height;
2513
2514     if (window_system_pixelated_geometry (frame))
2515       {
2516         pixel_to_real_char_size (f, FRAME_PIXWIDTH (f), FRAME_PIXHEIGHT (f),
2517                                  &width, &height);
2518       }
2519     else
2520       {
2521         height = FRAME_HEIGHT (f);
2522         width = FRAME_WIDTH (f);
2523       }
2524     result = cons3 (Qwidth , make_int (width),  result);
2525     result = cons3 (Qheight, make_int (height), result);
2526   }
2527
2528   result = cons3 (Qname, f->name, result);
2529
2530   UNGCPRO;
2531   return result;
2532 }
2533
2534 \f
2535 DEFUN ("frame-pixel-height", Fframe_pixel_height, 0, 1, 0, /*
2536 Return the height in pixels of FRAME.
2537 */
2538        (frame))
2539 {
2540   return make_int (decode_frame (frame)->pixheight);
2541 }
2542
2543 DEFUN ("frame-pixel-width", Fframe_pixel_width, 0, 1, 0, /*
2544 Return the width in pixels of FRAME.
2545 */
2546        (frame))
2547 {
2548   return make_int (decode_frame (frame)->pixwidth);
2549 }
2550
2551 DEFUN ("frame-name", Fframe_name, 0, 1, 0, /*
2552 Return the name of FRAME (defaulting to the selected frame).
2553 This is not the same as the `title' of the frame.
2554 */
2555        (frame))
2556 {
2557   return decode_frame (frame)->name;
2558 }
2559
2560 DEFUN ("frame-modified-tick", Fframe_modified_tick, 0, 1, 0, /*
2561 Return FRAME's tick counter, incremented for each change to the frame.
2562 Each frame has a tick counter which is incremented each time the frame
2563 is resized, a window is resized, added, or deleted, a face is changed,
2564 `set-window-buffer' or `select-window' is called on a window in the
2565 frame, the window-start of a window in the frame has changed, or
2566 anything else interesting has happened.  It wraps around occasionally.
2567 No argument or nil as argument means use selected frame as FRAME.
2568 */
2569        (frame))
2570 {
2571   return make_int (decode_frame (frame)->modiff);
2572 }
2573
2574 static void
2575 internal_set_frame_size (struct frame *f, int cols, int rows, int pretend)
2576 {
2577   /* An explicit size change cancels any pending frame size adjustment */
2578   CLEAR_FRAME_SIZE_SLIPPED(f);
2579
2580   if (pretend || !HAS_FRAMEMETH_P (f, set_frame_size))
2581     change_frame_size (f, rows, cols, 0);
2582   else
2583     FRAMEMETH (f, set_frame_size, (f, cols, rows));
2584 }
2585
2586 DEFUN ("set-frame-height", Fset_frame_height, 2, 3, 0, /*
2587 Specify that the frame FRAME has LINES lines.
2588 Optional third arg non-nil means that redisplay should use LINES lines
2589 but that the idea of the actual height of the frame should not be changed.
2590 */
2591        (frame, rows, pretend))
2592 {
2593   struct frame *f = decode_frame (frame);
2594   int height, width;
2595   XSETFRAME (frame, f);
2596   CHECK_INT (rows);
2597
2598   if (window_system_pixelated_geometry (frame))
2599     {
2600       char_to_real_pixel_size (f, 0, XINT (rows), 0, &height);
2601       width = FRAME_PIXWIDTH (f);
2602     }
2603   else
2604     {
2605       height = XINT (rows);
2606       width = FRAME_WIDTH (f);
2607     }
2608
2609   internal_set_frame_size (f, width, height, !NILP (pretend));
2610   return frame;
2611 }
2612
2613 DEFUN ("set-frame-width", Fset_frame_width, 2, 3, 0, /*
2614 Specify that the frame FRAME has COLS columns.
2615 Optional third arg non-nil means that redisplay should use COLS columns
2616 but that the idea of the actual width of the frame should not be changed.
2617 */
2618        (frame, cols, pretend))
2619 {
2620   struct frame *f = decode_frame (frame);
2621   int width, height;
2622   XSETFRAME (frame, f);
2623   CHECK_INT (cols);
2624
2625   if (window_system_pixelated_geometry (frame))
2626     {
2627       char_to_real_pixel_size (f, XINT (cols), 0, &width, 0);
2628       height = FRAME_PIXHEIGHT (f);
2629     }
2630   else
2631     {
2632       width = XINT (cols);
2633       height = FRAME_HEIGHT (f);
2634     }
2635
2636   internal_set_frame_size (f, width, height, !NILP (pretend));
2637   return frame;
2638 }
2639
2640 DEFUN ("set-frame-size", Fset_frame_size, 3, 4, 0, /*
2641 Set the size of FRAME to COLS by ROWS.
2642 Optional fourth arg non-nil means that redisplay should use COLS by ROWS
2643 but that the idea of the actual size of the frame should not be changed.
2644 */
2645        (frame, cols, rows, pretend))
2646 {
2647   struct frame *f = decode_frame (frame);
2648   int height, width;
2649   XSETFRAME (frame, f);
2650   CHECK_INT (cols);
2651   CHECK_INT (rows);
2652
2653   if (window_system_pixelated_geometry (frame))
2654     char_to_real_pixel_size (f, XINT (cols), XINT (rows), &width, &height);
2655   else
2656     {
2657       height = XINT (rows);
2658       width = XINT (cols);
2659     }
2660
2661   internal_set_frame_size (f, width, height, !NILP (pretend));
2662   return frame;
2663 }
2664
2665 DEFUN ("set-frame-position", Fset_frame_position, 3, 3, 0, /*
2666 Set position of FRAME in pixels to XOFFSET by YOFFSET.
2667 This is actually the position of the upper left corner of the frame.
2668 Negative values for XOFFSET or YOFFSET are interpreted relative to
2669 the rightmost or bottommost possible position (that stays within the screen).
2670 */
2671        (frame, xoffset, yoffset))
2672 {
2673   struct frame *f = decode_frame (frame);
2674   CHECK_INT (xoffset);
2675   CHECK_INT (yoffset);
2676
2677   MAYBE_FRAMEMETH (f, set_frame_position, (f, XINT (xoffset), XINT (yoffset)));
2678
2679   return Qt;
2680 }
2681
2682 \f
2683
2684 /* Frame size conversion functions moved here from EmacsFrame.c
2685    because they're generic and really don't belong in that file.
2686    Function get_default_char_pixel_size() removed because it's
2687    exactly the same as default_face_height_and_width(). */
2688 static void
2689 frame_conversion_internal (struct frame *f, int pixel_to_char,
2690                            int *pixel_width, int *pixel_height,
2691                            int *char_width, int *char_height,
2692                            int real_face)
2693 {
2694   int cpw;
2695   int cph;
2696   int egw;
2697   int obw, obh, bdr;
2698   Lisp_Object frame, window;
2699
2700   XSETFRAME (frame, f);
2701   if (real_face)
2702     default_face_height_and_width (frame, &cph, &cpw);
2703   else
2704     default_face_height_and_width_1 (frame, &cph, &cpw);
2705
2706   window = FRAME_SELECTED_WINDOW (f);
2707
2708   egw = max (glyph_width (Vcontinuation_glyph, window),
2709              glyph_width (Vtruncation_glyph, window));
2710   egw = max (egw, cpw);
2711   bdr = 2 * f->internal_border_width;
2712   obw = FRAME_SCROLLBAR_WIDTH (f) + FRAME_THEORETICAL_LEFT_TOOLBAR_WIDTH (f) +
2713     FRAME_THEORETICAL_RIGHT_TOOLBAR_WIDTH (f) +
2714     2 * FRAME_THEORETICAL_LEFT_TOOLBAR_BORDER_WIDTH (f) +
2715     2 * FRAME_THEORETICAL_RIGHT_TOOLBAR_BORDER_WIDTH (f);
2716   obh = FRAME_SCROLLBAR_HEIGHT (f) + FRAME_THEORETICAL_TOP_TOOLBAR_HEIGHT (f) +
2717     FRAME_THEORETICAL_BOTTOM_TOOLBAR_HEIGHT (f) +
2718     2 * FRAME_THEORETICAL_TOP_TOOLBAR_BORDER_WIDTH (f) +
2719     2 * FRAME_THEORETICAL_BOTTOM_TOOLBAR_BORDER_WIDTH (f);
2720
2721   if (pixel_to_char)
2722     {
2723       if (char_width)
2724         *char_width = 1 + ((*pixel_width - egw) - bdr - obw) / cpw;
2725       if (char_height)
2726         *char_height = (*pixel_height - bdr - obh) / cph;
2727     }
2728   else
2729     {
2730       if (pixel_width)
2731         *pixel_width = (*char_width - 1) * cpw + egw + bdr + obw;
2732       if (pixel_height)
2733         *pixel_height = *char_height * cph + bdr + obh;
2734     }
2735 }
2736
2737 /* This takes the size in pixels of the text area, and returns the number
2738    of characters that will fit there, taking into account the internal
2739    border width, and the pixel width of the line terminator glyphs (which
2740    always count as one "character" wide, even if they are not the same size
2741    as the default character size of the default font).  The frame scrollbar
2742    width and left and right toolbar widths are also subtracted out of the
2743    available width.  The frame scrollbar height and top and bottom toolbar
2744    heights are subtracted out of the available height.
2745
2746    Therefore the result is not necessarily a multiple of anything in
2747    particular.  */
2748 void
2749 pixel_to_char_size (struct frame *f, int pixel_width, int pixel_height,
2750                     int *char_width, int *char_height)
2751 {
2752   frame_conversion_internal (f, 1, &pixel_width, &pixel_height, char_width,
2753                              char_height, 0);
2754 }
2755
2756 /* Given a character size, this returns the minimum number of pixels
2757    necessary to display that many characters, taking into account the
2758    internal border width, scrollbar height and width, toolbar heights and
2759    widths and the size of the line terminator glyphs (assuming the line
2760    terminators take up exactly one character position).
2761
2762    Therefore the result is not necessarily a multiple of anything in
2763    particular.  */
2764 void
2765 char_to_pixel_size (struct frame *f, int char_width, int char_height,
2766                     int *pixel_width, int *pixel_height)
2767 {
2768   frame_conversion_internal (f, 0, pixel_width, pixel_height, &char_width,
2769                              &char_height, 0);
2770 }
2771
2772 /* Given a pixel size, rounds DOWN to the smallest size in pixels necessary
2773    to display the same number of characters as are displayable now.
2774  */
2775 void
2776 round_size_to_char (struct frame *f, int in_width, int in_height,
2777                     int *out_width, int *out_height)
2778 {
2779   int char_width;
2780   int char_height;
2781   pixel_to_char_size (f, in_width, in_height, &char_width, &char_height);
2782   char_to_pixel_size (f, char_width, char_height, out_width, out_height);
2783 }
2784
2785 /* Versions of the above which always account for real font metrics.
2786  */
2787 void
2788 pixel_to_real_char_size (struct frame *f, int pixel_width, int pixel_height,
2789                          int *char_width, int *char_height)
2790 {
2791   frame_conversion_internal (f, 1, &pixel_width, &pixel_height, char_width,
2792                              char_height, 1);
2793 }
2794
2795 void
2796 char_to_real_pixel_size (struct frame *f, int char_width, int char_height,
2797                          int *pixel_width, int *pixel_height)
2798 {
2799   frame_conversion_internal (f, 0, pixel_width, pixel_height, &char_width,
2800                              &char_height, 1);
2801 }
2802
2803 void
2804 round_size_to_real_char (struct frame *f, int in_width, int in_height,
2805                          int *out_width, int *out_height)
2806 {
2807   int char_width;
2808   int char_height;
2809   pixel_to_real_char_size (f, in_width, in_height, &char_width, &char_height);
2810   char_to_real_pixel_size (f, char_width, char_height, out_width, out_height);
2811 }
2812
2813 /* Change the frame height and/or width.  Values may be given as zero to
2814    indicate no change is to take place. */
2815 static void
2816 change_frame_size_1 (struct frame *f, int newheight, int newwidth)
2817 {
2818   Lisp_Object frame;
2819   int new_pixheight, new_pixwidth;
2820   int font_height, real_font_height, font_width;
2821
2822   /* #### Chuck -- shouldn't we be checking to see if the frame
2823      is being "changed" to its existing size, and do nothing if so? */
2824   /* No, because it would hose toolbar updates.  The toolbar
2825      update code relies on this function to cause window `top' and
2826      `left' coordinates to be recomputed even though no frame size
2827      change occurs. --kyle */
2828   if (in_display)
2829     abort ();
2830
2831   XSETFRAME (frame, f);
2832
2833   default_face_height_and_width (frame, &real_font_height, 0);
2834   default_face_height_and_width_1 (frame, &font_height, &font_width);
2835
2836   /* This size-change overrides any pending one for this frame.  */
2837   FRAME_NEW_HEIGHT (f) = 0;
2838   FRAME_NEW_WIDTH (f) = 0;
2839
2840   new_pixheight = newheight * font_height;
2841   new_pixwidth = (newwidth - 1) * font_width;
2842
2843   /* #### dependency on FRAME_WIN_P should be removed. */
2844   if (FRAME_WIN_P (f))
2845     {
2846       new_pixheight += FRAME_SCROLLBAR_HEIGHT (f);
2847       new_pixwidth += FRAME_SCROLLBAR_WIDTH (f);
2848     }
2849
2850   /* when frame_conversion_internal() calculated the number of rows/cols
2851      in the frame, the theoretical toolbar sizes were subtracted out.
2852      The calculations below adjust for real toolbar height/width in
2853      frame, which may be different from frame spec, taking the above
2854      fact into account */
2855   new_pixheight +=
2856     + FRAME_THEORETICAL_TOP_TOOLBAR_HEIGHT (f)
2857     + 2 * FRAME_THEORETICAL_TOP_TOOLBAR_BORDER_WIDTH (f)
2858     - FRAME_REAL_TOP_TOOLBAR_HEIGHT (f)
2859     - 2 * FRAME_REAL_TOP_TOOLBAR_BORDER_WIDTH (f);
2860
2861   new_pixheight +=
2862     + FRAME_THEORETICAL_BOTTOM_TOOLBAR_HEIGHT (f)
2863     + 2 * FRAME_THEORETICAL_BOTTOM_TOOLBAR_BORDER_WIDTH (f)
2864     - FRAME_REAL_BOTTOM_TOOLBAR_HEIGHT (f)
2865     - 2 * FRAME_REAL_BOTTOM_TOOLBAR_BORDER_WIDTH (f);
2866
2867   new_pixwidth +=
2868     + FRAME_THEORETICAL_LEFT_TOOLBAR_WIDTH (f)
2869     + 2 * FRAME_THEORETICAL_LEFT_TOOLBAR_BORDER_WIDTH (f)
2870     - FRAME_REAL_LEFT_TOOLBAR_WIDTH (f)
2871     - 2 * FRAME_REAL_LEFT_TOOLBAR_BORDER_WIDTH (f);
2872
2873   new_pixwidth +=
2874     + FRAME_THEORETICAL_RIGHT_TOOLBAR_WIDTH (f)
2875     + 2 * FRAME_THEORETICAL_RIGHT_TOOLBAR_BORDER_WIDTH (f)
2876     - FRAME_REAL_RIGHT_TOOLBAR_WIDTH (f)
2877     - 2 * FRAME_REAL_RIGHT_TOOLBAR_BORDER_WIDTH (f);
2878
2879   /* Adjust the width for the end glyph which may be a different width
2880      than the default character width. */
2881   {
2882     int adjustment, trunc_width, cont_width;
2883
2884     trunc_width = glyph_width (Vtruncation_glyph,
2885                                FRAME_SELECTED_WINDOW (f));
2886     cont_width = glyph_width (Vcontinuation_glyph,
2887                               FRAME_SELECTED_WINDOW (f));
2888     adjustment = max (trunc_width, cont_width);
2889     adjustment = max (adjustment, font_width);
2890
2891     new_pixwidth += adjustment;
2892   }
2893
2894   /* If we don't have valid values, exit. */
2895   if (!new_pixheight && !new_pixwidth)
2896     return;
2897
2898   if (new_pixheight)
2899     {
2900       XWINDOW (FRAME_ROOT_WINDOW (f))->pixel_top = FRAME_TOP_BORDER_END (f);
2901
2902       if (FRAME_HAS_MINIBUF_P (f)
2903           && ! FRAME_MINIBUF_ONLY_P (f))
2904         /* Frame has both root and minibuffer.  */
2905         {
2906           /*
2907            * Leave the minibuffer height the same if the frame has
2908            * been initialized, and the minibuffer height is tall
2909            * enough to display at least one line of text in the default
2910            * font, and the old minibuffer height is a multiple of the
2911            * default font height.  This should cause the minibuffer
2912            * height to be recomputed on font changes but not for
2913            * other frame size changes, which seems reasonable.
2914            */
2915           int old_minibuf_height =
2916             XWINDOW(FRAME_MINIBUF_WINDOW(f))->pixel_height;
2917           int minibuf_height =
2918             f->init_finished && (old_minibuf_height % real_font_height) == 0 ?
2919             max(old_minibuf_height, real_font_height) :
2920             real_font_height;
2921           set_window_pixheight (FRAME_ROOT_WINDOW (f),
2922                                 /* - font_height for minibuffer */
2923                                 new_pixheight - minibuf_height, 0);
2924
2925           XWINDOW (FRAME_MINIBUF_WINDOW (f))->pixel_top =
2926             new_pixheight - minibuf_height + FRAME_TOP_BORDER_END (f);
2927
2928           set_window_pixheight (FRAME_MINIBUF_WINDOW (f), minibuf_height, 0);
2929         }
2930       else
2931         /* Frame has just one top-level window.  */
2932         set_window_pixheight (FRAME_ROOT_WINDOW (f), new_pixheight, 0);
2933
2934       FRAME_HEIGHT (f) = newheight;
2935       if (FRAME_TTY_P (f))
2936         f->pixheight = newheight;
2937     }
2938
2939   if (new_pixwidth)
2940     {
2941       XWINDOW (FRAME_ROOT_WINDOW (f))->pixel_left = FRAME_LEFT_BORDER_END (f);
2942       set_window_pixwidth (FRAME_ROOT_WINDOW (f), new_pixwidth, 0);
2943
2944       if (FRAME_HAS_MINIBUF_P (f))
2945         {
2946           XWINDOW (FRAME_MINIBUF_WINDOW (f))->pixel_left =
2947             FRAME_LEFT_BORDER_END (f);
2948           set_window_pixwidth (FRAME_MINIBUF_WINDOW (f), new_pixwidth, 0);
2949         }
2950
2951       FRAME_WIDTH (f) = newwidth;
2952       if (FRAME_TTY_P (f))
2953         f->pixwidth = newwidth;
2954     }
2955
2956   if (window_system_pixelated_geometry (frame))
2957     pixel_to_real_char_size (f, FRAME_PIXWIDTH (f), FRAME_PIXHEIGHT (f),
2958                              &FRAME_CHARWIDTH (f), &FRAME_CHARHEIGHT (f));
2959   else
2960     {
2961       FRAME_CHARWIDTH (f) = FRAME_WIDTH (f);
2962       FRAME_CHARHEIGHT (f) = FRAME_HEIGHT (f);
2963     }
2964
2965   MARK_FRAME_TOOLBARS_CHANGED (f);
2966   MARK_FRAME_CHANGED (f);
2967   f->echo_area_garbaged = 1;
2968 }
2969
2970 void
2971 change_frame_size (struct frame *f, int newheight, int newwidth, int delay)
2972 {
2973   /* sometimes we get passed a size that's too small (esp. when a
2974      client widget gets resized, since we have no control over this).
2975      So deal. */
2976   check_frame_size (f, &newheight, &newwidth);
2977
2978   if (delay || in_display || gc_in_progress)
2979     {
2980       MARK_FRAME_SIZE_CHANGED (f);
2981       f->new_width = newwidth;
2982       f->new_height = newheight;
2983       return;
2984     }
2985
2986   f->size_change_pending = 0;
2987   /* For TTY frames, it's like one, like all ...
2988      Can't have two TTY frames of different sizes on the same device. */
2989   if (FRAME_TTY_P (f))
2990     {
2991       Lisp_Object frmcons;
2992
2993       DEVICE_FRAME_LOOP (frmcons, XDEVICE (FRAME_DEVICE (f)))
2994         change_frame_size_1 (XFRAME (XCAR (frmcons)), newheight, newwidth);
2995     }
2996   else
2997     change_frame_size_1 (f, newheight, newwidth);
2998 }
2999
3000 \f
3001 /* The caller is responsible for freeing the returned string. */
3002 static Bufbyte *
3003 generate_title_string (struct window *w, Lisp_Object format_str,
3004                        face_index findex, int type)
3005 {
3006   struct display_line *dl;
3007   struct display_block *db;
3008   int elt = 0;
3009
3010   dl = &title_string_display_line;
3011   db = get_display_block_from_line (dl, TEXT);
3012   Dynarr_reset (db->runes);
3013
3014   generate_formatted_string_db (format_str, Qnil, w, dl, db, findex, 0,
3015                                 -1, type);
3016
3017   Dynarr_reset (title_string_emchar_dynarr);
3018   while (elt < Dynarr_length (db->runes))
3019     {
3020       if (Dynarr_atp (db->runes, elt)->type == RUNE_CHAR)
3021         Dynarr_add (title_string_emchar_dynarr,
3022                     Dynarr_atp (db->runes, elt)->object.chr.ch);
3023       elt++;
3024     }
3025
3026   return
3027     convert_emchar_string_into_malloced_string
3028     (Dynarr_atp (title_string_emchar_dynarr, 0),
3029      Dynarr_length (title_string_emchar_dynarr), 0);
3030 }
3031
3032 void
3033 update_frame_title (struct frame *f)
3034 {
3035   struct window *w = XWINDOW (FRAME_SELECTED_WINDOW (f));
3036   Lisp_Object title_format;
3037   Lisp_Object icon_format;
3038   Bufbyte *title;
3039
3040   /* We don't change the title for the minibuffer unless the frame
3041      only has a minibuffer. */
3042   if (MINI_WINDOW_P (w) && !FRAME_MINIBUF_ONLY_P (f))
3043     return;
3044
3045   /* And we don't want dead buffers to blow up on us. */
3046   if (!BUFFER_LIVE_P (XBUFFER (w->buffer)))
3047     return;
3048
3049   title = NULL;
3050   title_format = symbol_value_in_buffer (Qframe_title_format,      w->buffer);
3051   icon_format  = symbol_value_in_buffer (Qframe_icon_title_format, w->buffer);
3052
3053   if (HAS_FRAMEMETH_P (f, set_title_from_bufbyte))
3054     {
3055       title = generate_title_string (w, title_format,
3056                                      DEFAULT_INDEX, CURRENT_DISP);
3057       FRAMEMETH (f, set_title_from_bufbyte, (f, title));
3058     }
3059
3060   if (HAS_FRAMEMETH_P (f, set_icon_name_from_bufbyte))
3061     {
3062       if (!EQ (icon_format, title_format) || !title)
3063         {
3064           if (title)
3065             xfree (title);
3066
3067           title = generate_title_string (w, icon_format,
3068                                          DEFAULT_INDEX, CURRENT_DISP);
3069         }
3070       FRAMEMETH (f, set_icon_name_from_bufbyte, (f, title));
3071     }
3072
3073   if (title)
3074     xfree (title);
3075 }
3076
3077 \f
3078 DEFUN ("set-frame-pointer", Fset_frame_pointer, 2, 2, 0, /*
3079 Set the mouse pointer of FRAME to the given pointer image instance.
3080 You should not call this function directly.  Instead, set one of
3081 the variables `text-pointer-glyph', `nontext-pointer-glyph',
3082 `modeline-pointer-glyph', `selection-pointer-glyph',
3083 `busy-pointer-glyph', or `toolbar-pointer-glyph'.
3084 */
3085        (frame, image_instance))
3086 {
3087   struct frame *f = decode_frame (frame);
3088   CHECK_POINTER_IMAGE_INSTANCE (image_instance);
3089   if (!EQ (f->pointer, image_instance))
3090     {
3091       f->pointer = image_instance;
3092       MAYBE_FRAMEMETH (f, set_frame_pointer, (f));
3093     }
3094   return Qnil;
3095 }
3096
3097 \f
3098 void
3099 update_frame_icon (struct frame *f)
3100 {
3101   if (f->icon_changed || f->windows_changed)
3102     {
3103       Lisp_Object frame;
3104       Lisp_Object new_icon;
3105
3106       XSETFRAME (frame, f);
3107       new_icon = glyph_image_instance (Vframe_icon_glyph, frame,
3108                                        ERROR_ME_WARN, 0);
3109       if (!EQ (new_icon, f->icon))
3110         {
3111           f->icon = new_icon;
3112           MAYBE_FRAMEMETH (f, set_frame_icon, (f));
3113         }
3114     }
3115
3116   f->icon_changed = 0;
3117 }
3118
3119 static void
3120 icon_glyph_changed (Lisp_Object glyph, Lisp_Object property,
3121                     Lisp_Object locale)
3122 {
3123   MARK_ICON_CHANGED;
3124 }
3125
3126 \f
3127 /***************************************************************************/
3128 /*                                                                         */
3129 /*                              initialization                             */
3130 /*                                                                         */
3131 /***************************************************************************/
3132
3133 void
3134 init_frame (void)
3135 {
3136 #ifndef PDUMP
3137   if (!initialized)
3138 #endif
3139     {
3140       title_string_emchar_dynarr = Dynarr_new (Emchar);
3141       xzero (title_string_display_line);
3142     }
3143 }
3144
3145 void
3146 syms_of_frame (void)
3147 {
3148   INIT_LRECORD_IMPLEMENTATION (frame);
3149
3150   defsymbol (&Qdelete_frame_hook, "delete-frame-hook");
3151   defsymbol (&Qselect_frame_hook, "select-frame-hook");
3152   defsymbol (&Qdeselect_frame_hook, "deselect-frame-hook");
3153   defsymbol (&Qcreate_frame_hook, "create-frame-hook");
3154   defsymbol (&Qcustom_initialize_frame, "custom-initialize-frame");
3155   defsymbol (&Qmouse_enter_frame_hook, "mouse-enter-frame-hook");
3156   defsymbol (&Qmouse_leave_frame_hook, "mouse-leave-frame-hook");
3157   defsymbol (&Qmap_frame_hook, "map-frame-hook");
3158   defsymbol (&Qunmap_frame_hook, "unmap-frame-hook");
3159
3160   defsymbol (&Qframep, "framep");
3161   defsymbol (&Qframe_live_p, "frame-live-p");
3162   defsymbol (&Qdelete_frame, "delete-frame");
3163   defsymbol (&Qsynchronize_minibuffers, "synchronize-minibuffers");
3164   defsymbol (&Qbuffer_predicate, "buffer-predicate");
3165   defsymbol (&Qframe_being_created, "frame-being-created");
3166   defsymbol (&Qmake_initial_minibuffer_frame, "make-initial-minibuffer-frame");
3167
3168   defsymbol (&Qframe_title_format, "frame-title-format");
3169   defsymbol (&Qframe_icon_title_format, "frame-icon-title-format");
3170
3171   defsymbol (&Qhidden, "hidden");
3172   defsymbol (&Qvisible, "visible");
3173   defsymbol (&Qiconic, "iconic");
3174   defsymbol (&Qinvisible, "invisible");
3175   defsymbol (&Qvisible_iconic, "visible-iconic");
3176   defsymbol (&Qinvisible_iconic, "invisible-iconic");
3177   defsymbol (&Qnomini, "nomini");
3178   defsymbol (&Qvisible_nomini, "visible-nomini");
3179   defsymbol (&Qiconic_nomini, "iconic-nomini");
3180   defsymbol (&Qinvisible_nomini, "invisible-nomini");
3181   defsymbol (&Qvisible_iconic_nomini, "visible-iconic-nomini");
3182   defsymbol (&Qinvisible_iconic_nomini, "invisible-iconic-nomini");
3183
3184   defsymbol (&Qminibuffer, "minibuffer");
3185   defsymbol (&Qunsplittable, "unsplittable");
3186   defsymbol (&Qinternal_border_width, "internal-border-width");
3187   defsymbol (&Qtop_toolbar_shadow_color, "top-toolbar-shadow-color");
3188   defsymbol (&Qbottom_toolbar_shadow_color, "bottom-toolbar-shadow-color");
3189   defsymbol (&Qbackground_toolbar_color, "background-toolbar-color");
3190   defsymbol (&Qtop_toolbar_shadow_pixmap, "top-toolbar-shadow-pixmap");
3191   defsymbol (&Qbottom_toolbar_shadow_pixmap, "bottom-toolbar-shadow-pixmap");
3192   defsymbol (&Qtoolbar_shadow_thickness, "toolbar-shadow-thickness");
3193   defsymbol (&Qscrollbar_placement, "scrollbar-placement");
3194   defsymbol (&Qinter_line_space, "inter-line-space");
3195   /* Qiconic already in this function. */
3196   defsymbol (&Qvisual_bell, "visual-bell");
3197   defsymbol (&Qbell_volume, "bell-volume");
3198   defsymbol (&Qpointer_background, "pointer-background");
3199   defsymbol (&Qpointer_color, "pointer-color");
3200   defsymbol (&Qtext_pointer, "text-pointer");
3201   defsymbol (&Qspace_pointer, "space-pointer");
3202   defsymbol (&Qmodeline_pointer, "modeline-pointer");
3203   defsymbol (&Qgc_pointer, "gc-pointer");
3204   defsymbol (&Qinitially_unmapped, "initially-unmapped");
3205   defsymbol (&Quse_backing_store, "use-backing-store");
3206   defsymbol (&Qborder_color, "border-color");
3207   defsymbol (&Qborder_width, "border-width");
3208   /* Qwidth, Qheight, Qleft, Qtop in general.c */
3209   defsymbol (&Qset_specifier, "set-specifier");
3210   defsymbol (&Qset_glyph_image, "set-glyph-image");
3211   defsymbol (&Qset_face_property, "set-face-property");
3212   defsymbol (&Qface_property_instance, "face-property-instance");
3213   defsymbol (&Qframe_property_alias, "frame-property-alias");
3214
3215   DEFSUBR (Fmake_frame);
3216   DEFSUBR (Fframep);
3217   DEFSUBR (Fframe_live_p);
3218 #if 0 /* FSFmacs */
3219   DEFSUBR (Fignore_event);
3220 #endif
3221   DEFSUBR (Ffocus_frame);
3222   DEFSUBR (Fselect_frame);
3223   DEFSUBR (Fselected_frame);
3224   DEFSUBR (Factive_minibuffer_window);
3225   DEFSUBR (Flast_nonminibuf_frame);
3226   DEFSUBR (Fframe_root_window);
3227   DEFSUBR (Fframe_selected_window);
3228   DEFSUBR (Fset_frame_selected_window);
3229   DEFSUBR (Fframe_device);
3230   DEFSUBR (Fnext_frame);
3231   DEFSUBR (Fprevious_frame);
3232   DEFSUBR (Fdelete_frame);
3233   DEFSUBR (Fmouse_position);
3234   DEFSUBR (Fmouse_pixel_position);
3235   DEFSUBR (Fmouse_position_as_motion_event);
3236   DEFSUBR (Fset_mouse_position);
3237   DEFSUBR (Fset_mouse_pixel_position);
3238   DEFSUBR (Fmake_frame_visible);
3239   DEFSUBR (Fmake_frame_invisible);
3240   DEFSUBR (Ficonify_frame);
3241   DEFSUBR (Fdeiconify_frame);
3242   DEFSUBR (Fframe_visible_p);
3243   DEFSUBR (Fframe_totally_visible_p);
3244   DEFSUBR (Fframe_iconified_p);
3245   DEFSUBR (Fvisible_frame_list);
3246   DEFSUBR (Fraise_frame);
3247   DEFSUBR (Flower_frame);
3248   DEFSUBR (Fframe_property);
3249   DEFSUBR (Fframe_properties);
3250   DEFSUBR (Fset_frame_properties);
3251   DEFSUBR (Fframe_pixel_height);
3252   DEFSUBR (Fframe_pixel_width);
3253   DEFSUBR (Fframe_name);
3254   DEFSUBR (Fframe_modified_tick);
3255   DEFSUBR (Fset_frame_height);
3256   DEFSUBR (Fset_frame_width);
3257   DEFSUBR (Fset_frame_size);
3258   DEFSUBR (Fset_frame_position);
3259   DEFSUBR (Fset_frame_pointer);
3260   DEFSUBR (Fprint_job_page_number);
3261   DEFSUBR (Fprint_job_eject_page);
3262 }
3263
3264 void
3265 vars_of_frame (void)
3266 {
3267   /* */
3268   Vframe_being_created = Qnil;
3269   staticpro (&Vframe_being_created);
3270
3271 #ifdef HAVE_CDE
3272   Fprovide (intern ("cde"));
3273 #endif
3274
3275 #ifdef HAVE_OFFIX_DND
3276   Fprovide (intern ("offix"));
3277 #endif
3278
3279 #if 0 /* FSFmacs stupidity */
3280   xxDEFVAR_LISP ("emacs-iconified", &Vemacs_iconified /*
3281 Non-nil if all of emacs is iconified and frame updates are not needed.
3282 */ );
3283   Vemacs_iconified = Qnil;
3284 #endif
3285
3286   DEFVAR_LISP ("select-frame-hook", &Vselect_frame_hook /*
3287 Function or functions to run just after a new frame is given the focus.
3288 Note that calling `select-frame' does not necessarily set the focus:
3289 The actual window-system focus will not be changed until the next time
3290 that XEmacs is waiting for an event, and even then, the window manager
3291 may refuse the focus-change request.
3292 */ );
3293   Vselect_frame_hook = Qnil;
3294
3295   DEFVAR_LISP ("deselect-frame-hook", &Vdeselect_frame_hook /*
3296 Function or functions to run just before a frame loses the focus.
3297 See `select-frame-hook'.
3298 */ );
3299   Vdeselect_frame_hook = Qnil;
3300
3301   DEFVAR_LISP ("delete-frame-hook", &Vdelete_frame_hook /*
3302 Function or functions to call when a frame is deleted.
3303 One argument, the about-to-be-deleted frame.
3304 */ );
3305   Vdelete_frame_hook = Qnil;
3306
3307   DEFVAR_LISP ("create-frame-hook", &Vcreate_frame_hook /*
3308 Function or functions to call when a frame is created.
3309 One argument, the newly-created frame.
3310 */ );
3311   Vcreate_frame_hook = Qnil;
3312
3313   DEFVAR_LISP ("mouse-enter-frame-hook", &Vmouse_enter_frame_hook /*
3314 Function or functions to call when the mouse enters a frame.
3315 One argument, the frame.
3316 Be careful not to make assumptions about the window manager's focus model.
3317 In most cases, the `deselect-frame-hook' is more appropriate.
3318 */ );
3319   Vmouse_enter_frame_hook = Qnil;
3320
3321   DEFVAR_LISP ("mouse-leave-frame-hook", &Vmouse_leave_frame_hook /*
3322 Function or functions to call when the mouse leaves a frame.
3323 One argument, the frame.
3324 Be careful not to make assumptions about the window manager's focus model.
3325 In most cases, the `select-frame-hook' is more appropriate.
3326 */ );
3327   Vmouse_leave_frame_hook = Qnil;
3328
3329   DEFVAR_LISP ("map-frame-hook", &Vmap_frame_hook /*
3330 Function or functions to call when a frame is mapped.
3331 One argument, the frame.
3332 */ );
3333   Vmap_frame_hook = Qnil;
3334
3335   DEFVAR_LISP ("unmap-frame-hook", &Vunmap_frame_hook /*
3336 Function or functions to call when a frame is unmapped.
3337 One argument, the frame.
3338 */ );
3339   Vunmap_frame_hook = Qnil;
3340
3341   DEFVAR_BOOL ("allow-deletion-of-last-visible-frame",
3342                &allow_deletion_of_last_visible_frame /*
3343 *Non-nil means to assume the force option to delete-frame.
3344 */ );
3345   allow_deletion_of_last_visible_frame = 0;
3346
3347   DEFVAR_LISP ("adjust-frame-function", &Vadjust_frame_function /*
3348 Function or constant controlling adjustment of frame.
3349 When scrollbars, toolbars, default font etc. change in frame, the frame
3350 needs to be adjusted. The adjustment is controlled by this variable.
3351 Legal values are:
3352   nil to keep character frame size unchanged when possible (resize)
3353   t   to keep pixel size unchanged (never resize)
3354   function symbol or lambda form. This function must return boolean
3355       value which is treated as above. Function is passed one parameter,
3356       the frame being adjusted. It function should not modify or delete
3357       the frame.
3358 */ );
3359   Vadjust_frame_function = Qnil;
3360
3361   DEFVAR_LISP ("mouse-motion-handler", &Vmouse_motion_handler /*
3362 Handler for motion events.  One arg, the event.
3363 For most applications, you should use `mode-motion-hook' instead of this.
3364 */ );
3365   Vmouse_motion_handler = Qnil;
3366
3367   DEFVAR_LISP ("synchronize-minibuffers",&Vsynchronize_minibuffers /*
3368 Set to t if all minibuffer windows are to be synchronized.
3369 This will cause echo area messages to appear in the minibuffers of all
3370 visible frames.
3371 */ );
3372   Vsynchronize_minibuffers = Qnil;
3373
3374   DEFVAR_LISP ("frame-title-format", &Vframe_title_format /*
3375 Controls the title of the X window corresponding to the selected frame.
3376 This is the same format as `modeline-format' with the exception that
3377 %- is ignored.
3378 */ );
3379   Vframe_title_format = build_string ("%S: %b");
3380
3381   DEFVAR_LISP ("frame-icon-title-format", &Vframe_icon_title_format /*
3382 Controls the title of the icon corresponding to the selected frame.
3383 See also the variable `frame-title-format'.
3384 */ );
3385   Vframe_icon_title_format = build_string ("%b");
3386
3387   DEFVAR_LISP ("default-frame-name", &Vdefault_frame_name /*
3388 The default name to assign to newly-created frames.
3389 This can be overridden by arguments to `make-frame'.
3390 This must be a string.
3391 */ );
3392 #ifndef INFODOCK
3393   Vdefault_frame_name = build_string ("emacs");
3394 #else
3395   Vdefault_frame_name = build_string ("InfoDock");
3396 #endif
3397
3398   DEFVAR_LISP ("default-frame-plist", &Vdefault_frame_plist /*
3399 Plist of default values for frame creation, other than the first one.
3400 These may be set in your init file, like this:
3401
3402   \(setq default-frame-plist '(width 80 height 55))
3403
3404 The properties may be in alist format for backward compatibility
3405 but you should not rely on this behavior.
3406
3407 These override values given in window system configuration data,
3408  including X Windows' defaults database.
3409
3410 Since the first X frame is created before loading your .emacs file,
3411 you must use the X resource database for that.
3412
3413 For values specific to the first Emacs frame, see `initial-frame-plist'.
3414 For values specific to the separate minibuffer frame, see
3415  `minibuffer-frame-plist'.
3416
3417 See also the variables `default-x-frame-plist' and
3418 `default-tty-frame-plist', which are like `default-frame-plist'
3419 except that they apply only to X or tty frames, respectively
3420 \(whereas `default-frame-plist' applies to all types of frames).
3421 */ );
3422   Vdefault_frame_plist = Qnil;
3423
3424   DEFVAR_LISP ("frame-icon-glyph", &Vframe_icon_glyph /*
3425 Icon glyph used to iconify a frame.
3426 */ );
3427 }
3428
3429 void
3430 complex_vars_of_frame (void)
3431 {
3432   Vframe_icon_glyph = allocate_glyph (GLYPH_ICON, icon_glyph_changed);
3433 }