home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / emacs-19.28-src.tgz / tar.out / fsf / emacs / src / frame.c < prev    next >
C/C++ Source or Header  |  1996-09-28  |  65KB  |  2,323 lines

  1. /* Generic frame functions.
  2.    Copyright (C) 1993, 1994 Free Software Foundation.
  3.  
  4. This file is part of GNU Emacs.
  5.  
  6. GNU Emacs is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2, or (at your option)
  9. any later version.
  10.  
  11. GNU Emacs is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GNU Emacs; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. #include <config.h>
  21.  
  22. #include <stdio.h>
  23. #include "lisp.h"
  24. #include "frame.h"
  25. #include "termhooks.h"
  26. #include "window.h"
  27.  
  28. #ifdef USE_PROTOS
  29. #include "protos.h"
  30. #endif
  31.  
  32. /* CHFIXME: cleanup HAVE_MOUSE changes, add staticpro, cleanup AMIGA changes (undo/change MULTI_FRAME changes) */
  33. #ifdef AMIGA /* CHFIXME */
  34. #include "amiga.h"
  35. #endif
  36.  
  37. #ifdef MULTI_FRAME
  38.  
  39. #include "buffer.h"
  40.  
  41. /* These help us bind and responding to switch-frame events.  */
  42. #include "commands.h"
  43. #include "keyboard.h"
  44.  
  45. Lisp_Object Vemacs_iconified;
  46. Lisp_Object Vframe_list;
  47. Lisp_Object Vterminal_frame;
  48. Lisp_Object Vdefault_minibuffer_frame;
  49. Lisp_Object Vdefault_frame_alist;
  50.  
  51. /* Evaluate this expression to rebuild the section of syms_of_frame
  52.    that initializes and staticpros the symbols declared below.  Note
  53.    that Emacs 18 has a bug that keeps C-x C-e from being able to
  54.    evaluate this expression.
  55.  
  56. (progn
  57.   ;; Accumulate a list of the symbols we want to initialize from the
  58.   ;; declarations at the top of the file.
  59.   (goto-char (point-min))
  60.   (search-forward "/\*&&& symbols declared here &&&*\/\n")
  61.   (let (symbol-list)
  62.     (while (looking-at "Lisp_Object \\(Q[a-z_]+\\)")
  63.       (setq symbol-list
  64.         (cons (buffer-substring (match-beginning 1) (match-end 1))
  65.           symbol-list))
  66.       (forward-line 1))
  67.     (setq symbol-list (nreverse symbol-list))
  68.     ;; Delete the section of syms_of_... where we initialize the symbols.
  69.     (search-forward "\n  /\*&&& init symbols here &&&*\/\n")
  70.     (let ((start (point)))
  71.       (while (looking-at "^  Q")
  72.     (forward-line 2))
  73.       (kill-region start (point)))
  74.     ;; Write a new symbol initialization section.
  75.     (while symbol-list
  76.       (insert (format "  %s = intern (\"" (car symbol-list)))
  77.       (let ((start (point)))
  78.     (insert (substring (car symbol-list) 1))
  79.     (subst-char-in-region start (point) ?_ ?-))
  80.       (insert (format "\");\n  staticpro (&%s);\n" (car symbol-list)))
  81.       (setq symbol-list (cdr symbol-list)))))
  82.   */        
  83.  
  84. /*&&& symbols declared here &&&*/
  85. Lisp_Object Qframep;
  86. Lisp_Object Qframe_live_p;
  87. Lisp_Object Qheight;
  88. Lisp_Object Qicon;
  89. Lisp_Object Qminibuffer;
  90. Lisp_Object Qmodeline;
  91. Lisp_Object Qname;
  92. Lisp_Object Qonly;
  93. Lisp_Object Qunsplittable;
  94. Lisp_Object Qmenu_bar_lines;
  95. Lisp_Object Qwidth;
  96. Lisp_Object Qx;
  97. Lisp_Object Qvisible;
  98.  
  99. extern Lisp_Object Vminibuffer_list;
  100. extern Lisp_Object get_minibuffer ();
  101. extern Lisp_Object Fhandle_switch_frame ();
  102. extern Lisp_Object Fredirect_frame_focus ();
  103.  
  104. DEFUN ("framep", Fframep, Sframep, 1, 1, 0,
  105.   "Return non-nil if OBJECT is a frame.\n\
  106. Value is t for a termcap frame (a character-only terminal),\n\
  107. `x' for an Emacs frame that is really an X window.\n\
  108. Also see `live-frame-p'.")
  109.   (object)
  110.      Lisp_Object object;
  111. {
  112.   if (XTYPE (object) != Lisp_Frame)
  113.     return Qnil;
  114.   switch (XFRAME (object)->output_method)
  115.     {
  116.     case output_termcap:
  117.       return Qt;
  118.     case output_x_window:
  119.       return Qx;
  120.     default:
  121.       abort ();
  122.     }
  123. }
  124.  
  125. DEFUN ("frame-live-p", Fframe_live_p, Sframe_live_p, 1, 1, 0,
  126.   "Return non-nil if OBJECT is a frame which has not been deleted.\n\
  127. Value is nil if OBJECT is not a live frame.  If object is a live\n\
  128. frame, the return value indicates what sort of output device it is\n\
  129. displayed on.  Value is t for a termcap frame (a character-only\n\
  130. terminal), `x' for an Emacs frame being displayed in an X window.")
  131.   (object)
  132.      Lisp_Object object;
  133. {
  134.   return ((FRAMEP (object)
  135.        && FRAME_LIVE_P (XFRAME (object)))
  136.       ? Fframep (object)
  137.       : Qnil);
  138. }
  139.  
  140. struct frame *
  141. make_frame (mini_p)
  142.      int mini_p;
  143. {
  144.   Lisp_Object frame;
  145.   register struct frame *f;
  146.   register Lisp_Object root_window;
  147.   register Lisp_Object mini_window;
  148.  
  149.   frame = Fmake_vector (((sizeof (struct frame) - (sizeof (Lisp_Vector)
  150.                              - sizeof (Lisp_Object)))
  151.               / sizeof (Lisp_Object)),
  152.              make_number (0));
  153.   XSETTYPE (frame, Lisp_Frame);
  154.   f = XFRAME (frame);
  155.  
  156.   f->cursor_x = 0;
  157.   f->cursor_y = 0;
  158.   f->current_glyphs = 0;
  159.   f->desired_glyphs = 0;
  160.   f->visible = 0;
  161.   f->async_visible = 0;
  162.   f->display.nothing = 0;
  163.   f->iconified = 0;
  164.   f->async_iconified = 0;
  165.   f->wants_modeline = 1;
  166.   f->auto_raise = 0;
  167.   f->auto_lower = 0;
  168.   f->no_split = 0;
  169.   f->garbaged = 0;
  170.   f->has_minibuffer = mini_p;
  171.   f->focus_frame = Qnil;
  172.   f->explicit_name = 0;
  173.   f->can_have_scroll_bars = 0;
  174.   f->has_vertical_scroll_bars = 0;
  175.   f->param_alist = Qnil;
  176.   f->scroll_bars = Qnil;
  177.   f->condemned_scroll_bars = Qnil;
  178.   f->face_alist = Qnil;
  179.   f->menu_bar_items = Qnil;
  180.   f->menu_bar_vector = Qnil;
  181.   f->menu_bar_items_used = 0;
  182.  
  183.   root_window = make_window ();
  184.   if (mini_p)
  185.     {
  186.       mini_window = make_window ();
  187.       XWINDOW (root_window)->next = mini_window;
  188.       XWINDOW (mini_window)->prev = root_window;
  189.       XWINDOW (mini_window)->mini_p = Qt;
  190.       XWINDOW (mini_window)->frame = frame;
  191.       f->minibuffer_window = mini_window;
  192.     }
  193.   else
  194.     {
  195.       mini_window = Qnil;
  196.       XWINDOW (root_window)->next = Qnil;
  197.       f->minibuffer_window = Qnil;
  198.     }
  199.  
  200.   XWINDOW (root_window)->frame = frame;
  201.  
  202.   /* 10 is arbitrary,
  203.      just so that there is "something there."
  204.      Correct size will be set up later with change_frame_size.  */
  205.  
  206.   f->width = 10;
  207.   f->height = 10;
  208.  
  209.   XFASTINT (XWINDOW (root_window)->width) = 10;
  210.   XFASTINT (XWINDOW (root_window)->height) = (mini_p ? 9 : 10);
  211.  
  212.   if (mini_p)
  213.     {
  214.       XFASTINT (XWINDOW (mini_window)->width) = 10;
  215.       XFASTINT (XWINDOW (mini_window)->top) = 9;
  216.       XFASTINT (XWINDOW (mini_window)->height) = 1;
  217.     }
  218.  
  219.   /* Choose a buffer for the frame's root window.  */
  220.   {
  221.     Lisp_Object buf;
  222.  
  223.     XWINDOW (root_window)->buffer = Qt;
  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 (XSTRING (Fbuffer_name (buf))->data[0] == ' ')
  228.       buf = Fother_buffer (buf, Qnil);
  229.     Fset_window_buffer (root_window, buf);
  230.   }
  231.  
  232.   if (mini_p)
  233.     {
  234.       XWINDOW (mini_window)->buffer = Qt;
  235.       Fset_window_buffer (mini_window,
  236.               (NILP (Vminibuffer_list)
  237.                ? get_minibuffer (0)
  238.                : Fcar (Vminibuffer_list)));
  239.     }
  240.  
  241.   f->root_window = root_window;
  242.   f->selected_window = root_window;
  243.   /* Make sure this window seems more recently used than
  244.      a newly-created, never-selected window.  */
  245.   XFASTINT (XWINDOW (f->selected_window)->use_time) = ++window_select_count;
  246.  
  247.   return f;
  248. }
  249.  
  250. /* Make a frame using a separate minibuffer window on another frame.
  251.    MINI_WINDOW is the minibuffer window to use.  nil means use the
  252.    default (the global minibuffer).  */
  253.  
  254. struct frame *
  255. make_frame_without_minibuffer (mini_window)
  256.      register Lisp_Object mini_window;
  257. {
  258.   register struct frame *f;
  259.  
  260.   /* Choose the minibuffer window to use.  */
  261.   if (NILP (mini_window))
  262.     {
  263.       if (XTYPE (Vdefault_minibuffer_frame) != Lisp_Frame)
  264.     error ("default-minibuffer-frame must be set when creating minibufferless frames");
  265.       if (! FRAME_LIVE_P (XFRAME (Vdefault_minibuffer_frame)))
  266.     error ("default-minibuffer-frame must be a live frame");
  267.       mini_window = XFRAME (Vdefault_minibuffer_frame)->minibuffer_window;
  268.     }
  269.   else
  270.     {
  271.       CHECK_LIVE_WINDOW (mini_window, 0);
  272.     }
  273.  
  274.   /* Make a frame containing just a root window.  */
  275.   f = make_frame (0);
  276.  
  277.   /* Install the chosen minibuffer window, with proper buffer.  */
  278.   f->minibuffer_window = mini_window;
  279.   Fset_window_buffer (mini_window,
  280.               (NILP (Vminibuffer_list)
  281.                ? get_minibuffer (0)
  282.                : Fcar (Vminibuffer_list)));
  283.   return f;
  284. }
  285.  
  286. /* Make a frame containing only a minibuffer window.  */
  287.  
  288. struct frame *
  289. make_minibuffer_frame ()
  290. {
  291.   /* First make a frame containing just a root window, no minibuffer.  */
  292.  
  293.   register struct frame *f = make_frame (0);
  294.   register Lisp_Object mini_window;
  295.   register Lisp_Object frame;
  296.  
  297.   XSET (frame, Lisp_Frame, f);
  298.  
  299.   f->auto_raise = 0;
  300.   f->auto_lower = 0;
  301.   f->no_split = 1;
  302.   f->wants_modeline = 0;
  303.   f->has_minibuffer = 1;
  304.  
  305.   /* Now label the root window as also being the minibuffer.
  306.      Avoid infinite looping on the window chain by marking next pointer
  307.      as nil. */
  308.  
  309.   mini_window = f->minibuffer_window = f->root_window;
  310.   XWINDOW (mini_window)->mini_p = Qt;
  311.   XWINDOW (mini_window)->next = Qnil;
  312.   XWINDOW (mini_window)->prev = Qnil;
  313.   XWINDOW (mini_window)->frame = frame;
  314.  
  315.   /* Put the proper buffer in that window.  */
  316.  
  317.   Fset_window_buffer (mini_window,
  318.               (NILP (Vminibuffer_list)
  319.                ? get_minibuffer (0)
  320.                : Fcar (Vminibuffer_list)));
  321.   return f;
  322. }
  323.  
  324. /* Construct a frame that refers to the terminal (stdin and stdout).  */
  325.  
  326. struct frame *
  327. make_terminal_frame ()
  328. {
  329.   register struct frame *f;
  330.   Lisp_Object frame;
  331.  
  332.   Vframe_list = Qnil;
  333.   f = make_frame (1);
  334.  
  335.   XSET (frame, Lisp_Frame, f);
  336.   Vframe_list = Fcons (frame, Vframe_list);
  337.  
  338.   f->name = build_string ("terminal");
  339.   FRAME_SET_VISIBLE (f, 1);
  340.   f->display.nothing = 1;   /* Nonzero means frame isn't deleted.  */
  341.   XSET (Vterminal_frame, Lisp_Frame, f);
  342.   return f;
  343. }
  344.  
  345. static Lisp_Object
  346. do_switch_frame (frame, no_enter, track)
  347.      Lisp_Object frame, no_enter;
  348.      int track;
  349. {
  350.   /* If FRAME is a switch-frame event, extract the frame we should
  351.      switch to.  */
  352.   if (CONSP (frame)
  353.       && EQ (XCONS (frame)->car, Qswitch_frame)
  354.       && CONSP (XCONS (frame)->cdr))
  355.     frame = XCONS (XCONS (frame)->cdr)->car;
  356.  
  357.   /* This used to say CHECK_LIVE_FRAME, but apparently it's possible for
  358.      a switch-frame event to arrive after a frame is no longer live,
  359.      especially when deleting the initial frame during startup.  */
  360.   CHECK_FRAME (frame, 0);
  361.   if (! FRAME_LIVE_P (XFRAME (frame)))
  362.     return Qnil;
  363.  
  364.   if (selected_frame == XFRAME (frame))
  365.     return frame;
  366.  
  367.   /* This is too greedy; it causes inappropriate focus redirection
  368.      that's hard to get rid of.  */
  369. #if 0
  370.   /* If a frame's focus has been redirected toward the currently
  371.      selected frame, we should change the redirection to point to the
  372.      newly selected frame.  This means that if the focus is redirected
  373.      from a minibufferless frame to a surrogate minibuffer frame, we
  374.      can use `other-window' to switch between all the frames using
  375.      that minibuffer frame, and the focus redirection will follow us
  376.      around.  */
  377.   if (track)
  378.     {
  379.       Lisp_Object tail;
  380.  
  381.       for (tail = Vframe_list; CONSP (tail); tail = XCONS (tail)->cdr)
  382.     {
  383.       Lisp_Object focus;
  384.  
  385.       if (XTYPE (XCONS (tail)->car) != Lisp_Frame)
  386.         abort ();
  387.  
  388.       focus = FRAME_FOCUS_FRAME (XFRAME (XCONS (tail)->car));
  389.  
  390.       if (XTYPE (focus) == Lisp_Frame
  391.           && XFRAME (focus) == selected_frame)
  392.         Fredirect_frame_focus (XCONS (tail)->car, frame);
  393.     }
  394.     }
  395. #else /* ! 0 */
  396.   /* Instead, apply it only to the frame we're pointing to.  */
  397. #ifdef HAVE_X_WINDOWS
  398.   if (track)
  399.     {
  400.       Lisp_Object focus, xfocus;
  401.  
  402.       xfocus = x_get_focus_frame ();
  403.       if (FRAMEP (xfocus))
  404.     {
  405.       focus = FRAME_FOCUS_FRAME (XFRAME (xfocus));
  406.       if (FRAMEP (focus) && XFRAME (focus) == selected_frame)
  407.         Fredirect_frame_focus (xfocus, frame);
  408.     }
  409.     }
  410. #endif /* HAVE_X_WINDOWS */
  411. #endif /* ! 0 */
  412.  
  413.   selected_frame = XFRAME (frame);
  414.   if (! FRAME_MINIBUF_ONLY_P (selected_frame))
  415.     last_nonminibuf_frame = selected_frame;
  416.  
  417.   Fselect_window (XFRAME (frame)->selected_window);
  418.   choose_minibuf_frame ();
  419.  
  420.   /* We want to make sure that the next event generates a frame-switch
  421.      event to the appropriate frame.  This seems kludgy to me, but
  422.      before you take it out, make sure that evaluating something like
  423.      (select-window (frame-root-window (new-frame))) doesn't end up
  424.      with your typing being interpreted in the new frame instead of
  425.      the one you're actually typing in.  */
  426.   internal_last_event_frame = Qnil;
  427.  
  428.   return frame;
  429. }
  430.  
  431. DEFUN ("select-frame", Fselect_frame, Sselect_frame, 1, 2, "e",
  432.   "Select the frame FRAME.\n\
  433. Subsequent editing commands apply to its selected window.\n\
  434. The selection of FRAME lasts until the next time the user does\n\
  435. something to select a different frame, or until the next time this\n\
  436. function is called.")
  437.   (frame, no_enter)
  438.     Lisp_Object frame, no_enter;
  439. {
  440.   return do_switch_frame (frame, no_enter, 1);
  441. }
  442.  
  443.  
  444. DEFUN ("handle-switch-frame", Fhandle_switch_frame, Shandle_switch_frame, 1, 2, "e",
  445.   "Handle a switch-frame event EVENT.\n\
  446. Switch-frame events are usually bound to this function.\n\
  447. A switch-frame event tells Emacs that the window manager has requested\n\
  448. that the user's events be directed to the frame mentioned in the event.\n\
  449. This function selects the selected window of the frame of EVENT.\n\
  450. \n\
  451. If EVENT is frame object, handle it as if it were a switch-frame event\n\
  452. to that frame.")
  453.   (frame, no_enter)
  454.      Lisp_Object frame, no_enter;
  455. {
  456.   return do_switch_frame (frame, no_enter, 0);
  457. }
  458.  
  459.  
  460. DEFUN ("selected-frame", Fselected_frame, Sselected_frame, 0, 0, 0,
  461.   "Return the frame that is now selected.")
  462.   ()
  463. {
  464.   Lisp_Object tem;
  465.   XSET (tem, Lisp_Frame, selected_frame);
  466.   return tem;
  467. }
  468.  
  469. DEFUN ("window-frame", Fwindow_frame, Swindow_frame, 1, 1, 0,
  470.   "Return the frame object that window WINDOW is on.")
  471.   (window)
  472.      Lisp_Object window;
  473. {
  474.   CHECK_LIVE_WINDOW (window, 0);
  475.   return XWINDOW (window)->frame;
  476. }
  477.  
  478. DEFUN ("frame-first-window", Fframe_first_window, Sframe_first_window, 0, 1, 0,
  479.   "Returns the topmost, leftmost window of FRAME.\n\
  480. If omitted, FRAME defaults to the currently selected frame.")
  481.   (frame)
  482.      Lisp_Object frame;
  483. {
  484.   Lisp_Object w;
  485.  
  486.   if (NILP (frame))
  487.     w = selected_frame->root_window;
  488.   else
  489.     {
  490.       CHECK_LIVE_FRAME (frame, 0);
  491.       w = XFRAME (frame)->root_window;
  492.     }
  493.   while (NILP (XWINDOW (w)->buffer))
  494.     {
  495.       if (! NILP (XWINDOW (w)->hchild))
  496.     w = XWINDOW (w)->hchild;
  497.       else if (! NILP (XWINDOW (w)->vchild))
  498.     w = XWINDOW (w)->vchild;
  499.       else
  500.     abort ();
  501.     }
  502.   return w;
  503. }
  504.  
  505. DEFUN ("frame-root-window", Fframe_root_window, Sframe_root_window, 0, 1, 0,
  506.        "Returns the root-window of FRAME.\n\
  507. If omitted, FRAME defaults to the currently selected frame.")
  508.   (frame)
  509.      Lisp_Object frame;
  510. {
  511.   if (NILP (frame))
  512.     XSET (frame, Lisp_Frame, selected_frame);
  513.   else
  514.     CHECK_LIVE_FRAME (frame, 0);
  515.  
  516.   return XFRAME (frame)->root_window;
  517. }
  518.  
  519. DEFUN ("frame-selected-window", Fframe_selected_window,
  520.        Sframe_selected_window, 0, 1, 0,
  521.   "Return the selected window of frame object FRAME.\n\
  522. If omitted, FRAME defaults to the currently selected frame.")
  523.   (frame)
  524.      Lisp_Object frame;
  525. {
  526.   if (NILP (frame))
  527.     XSET (frame, Lisp_Frame, selected_frame);
  528.   else
  529.     CHECK_LIVE_FRAME (frame, 0);
  530.  
  531.   return XFRAME (frame)->selected_window;
  532. }
  533.  
  534. DEFUN ("set-frame-selected-window", Fset_frame_selected_window,
  535.        Sset_frame_selected_window, 2, 2, 0,
  536.   "Set the selected window of frame object FRAME to WINDOW.\n\
  537. If FRAME is nil, the selected frame is used.\n\
  538. If FRAME is the selected frame, this makes WINDOW the selected window.")
  539.   (frame, window)
  540.      Lisp_Object frame, window;
  541. {
  542.   if (NILP (frame))
  543.     XSET (frame, Lisp_Frame, selected_frame);
  544.   else
  545.     CHECK_LIVE_FRAME (frame, 0);
  546.  
  547.   CHECK_LIVE_WINDOW (window, 1);
  548.  
  549.   if (! EQ (frame, WINDOW_FRAME (XWINDOW (window))))
  550.     error ("In `set-frame-selected-window', WINDOW is not on FRAME");
  551.  
  552.   if (XFRAME (frame) == selected_frame)
  553.     return Fselect_window (window);
  554.  
  555.   return XFRAME (frame)->selected_window = window;
  556. }
  557.  
  558. DEFUN ("frame-list", Fframe_list, Sframe_list,
  559.        0, 0, 0,
  560.        "Return a list of all frames.")
  561.   ()
  562. {
  563.   return Fcopy_sequence (Vframe_list);
  564. }
  565.  
  566. /* Return the next frame in the frame list after FRAME.
  567.    If MINIBUF is nil, exclude minibuffer-only frames.
  568.    If MINIBUF is a window, include only its own frame
  569.    and any frame now using that window as the minibuffer.
  570.    If MINIBUF is `visible', include all visible frames.
  571.    If MINIBUF is 0, include all visible and iconified frames.
  572.    Otherwise, include all frames.  */
  573.  
  574. Lisp_Object
  575. next_frame (frame, minibuf)
  576.      Lisp_Object frame;
  577.      Lisp_Object minibuf;
  578. {
  579.   Lisp_Object tail;
  580.   int passed = 0;
  581.  
  582.   /* There must always be at least one frame in Vframe_list.  */
  583.   if (! CONSP (Vframe_list))
  584.     abort ();
  585.  
  586.   /* If this frame is dead, it won't be in Vframe_list, and we'll loop
  587.      forever.  Forestall that.  */
  588.   CHECK_LIVE_FRAME (frame, 0);
  589.  
  590.   while (1)
  591.     for (tail = Vframe_list; CONSP (tail); tail = XCONS (tail)->cdr)
  592.       {
  593.     Lisp_Object f;
  594.  
  595.     f = XCONS (tail)->car;
  596.     if (passed)
  597.       {
  598.         /* Decide whether this frame is eligible to be returned.  */
  599.  
  600.         /* If we've looped all the way around without finding any
  601.            eligible frames, return the original frame.  */
  602.         if (EQ (f, frame))
  603.           return f;
  604.  
  605.         /* Let minibuf decide if this frame is acceptable.  */
  606.         if (NILP (minibuf))
  607.           {
  608.         if (! FRAME_MINIBUF_ONLY_P (XFRAME (f)))
  609.           return f;
  610.           }
  611.         else if (EQ (minibuf, Qvisible))
  612.           {
  613.         FRAME_SAMPLE_VISIBILITY (XFRAME (f));
  614.         if (FRAME_VISIBLE_P (XFRAME (f)))
  615.           return f;
  616.           }
  617.         else if (XFASTINT (minibuf) == 0)
  618.           {
  619.         FRAME_SAMPLE_VISIBILITY (XFRAME (f));
  620.         if (FRAME_VISIBLE_P (XFRAME (f))
  621.             || FRAME_ICONIFIED_P (XFRAME (f)))
  622.           return f;
  623.           }
  624.         else if (WINDOWP (minibuf))
  625.           {
  626.         if (EQ (FRAME_MINIBUF_WINDOW (XFRAME (f)), minibuf)
  627.             /* Check that F either is, or has forwarded its focus to,
  628.                MINIBUF's frame.  */
  629.             && (EQ (WINDOW_FRAME (XWINDOW (minibuf)), f)
  630.             || EQ (WINDOW_FRAME (XWINDOW (minibuf)),
  631.                    FRAME_FOCUS_FRAME (XFRAME (f)))))
  632.           return f;
  633.           }
  634.         else
  635.           return f;
  636.       }
  637.  
  638.     if (EQ (frame, f))
  639.       passed++;
  640.       }
  641. }
  642.  
  643. /* Return the previous frame in the frame list before FRAME.
  644.    If MINIBUF is nil, exclude minibuffer-only frames.
  645.    If MINIBUF is a window, include only its own frame
  646.    and any frame now using that window as the minibuffer.
  647.    If MINIBUF is `visible', include all visible frames.
  648.    If MINIBUF is 0, include all visible and iconified frames.
  649.    Otherwise, include all frames.  */
  650.  
  651. Lisp_Object
  652. prev_frame (frame, minibuf)
  653.      Lisp_Object frame;
  654.      Lisp_Object minibuf;
  655. {
  656.   Lisp_Object tail;
  657.   Lisp_Object prev;
  658.  
  659.   /* There must always be at least one frame in Vframe_list.  */
  660.   if (! CONSP (Vframe_list))
  661.     abort ();
  662.  
  663.   prev = Qnil;
  664.   for (tail = Vframe_list; CONSP (tail); tail = XCONS (tail)->cdr)
  665.     {
  666.       Lisp_Object f;
  667.  
  668.       f = XCONS (tail)->car;
  669.       if (XTYPE (f) != Lisp_Frame)
  670.     abort ();
  671.  
  672.       if (EQ (frame, f) && !NILP (prev))
  673.     return prev;
  674.  
  675.       /* Decide whether this frame is eligible to be returned,
  676.      according to minibuf.  */
  677.       if (NILP (minibuf))
  678.     {
  679.       if (! FRAME_MINIBUF_ONLY_P (XFRAME (f)))
  680.         prev = f;
  681.     }
  682.       else if (XTYPE (minibuf) == Lisp_Window)
  683.     {
  684.       if (EQ (FRAME_MINIBUF_WINDOW (XFRAME (f)), minibuf)
  685.           /* Check that F either is, or has forwarded its focus to,
  686.          MINIBUF's frame.  */
  687.           && (EQ (WINDOW_FRAME (XWINDOW (minibuf)), f)
  688.           || EQ (WINDOW_FRAME (XWINDOW (minibuf)),
  689.              FRAME_FOCUS_FRAME (XFRAME (f)))))
  690.         prev = f;
  691.     }
  692.       else if (EQ (minibuf, Qvisible))
  693.     {
  694.       FRAME_SAMPLE_VISIBILITY (XFRAME (f));
  695.       if (FRAME_VISIBLE_P (XFRAME (f)))
  696.         prev = f;
  697.     }
  698.       else if (XFASTINT (f) == 0)
  699.     {
  700.       FRAME_SAMPLE_VISIBILITY (XFRAME (f));
  701.       if (FRAME_VISIBLE_P (XFRAME (f))
  702.           || FRAME_ICONIFIED_P (XFRAME (f)))
  703.         prev = f;
  704.     }
  705.       else
  706.     prev = f;
  707.     }
  708.  
  709.   /* We've scanned the entire list.  */
  710.   if (NILP (prev))
  711.     /* We went through the whole frame list without finding a single
  712.        acceptable frame.  Return the original frame.  */
  713.     return frame;
  714.   else
  715.     /* There were no acceptable frames in the list before FRAME; otherwise,
  716.        we would have returned directly from the loop.  Since PREV is the last
  717.        acceptable frame in the list, return it.  */
  718.     return prev;
  719. }
  720.  
  721.  
  722. DEFUN ("next-frame", Fnext_frame, Snext_frame, 0, 2, 0,
  723.   "Return the next frame in the frame list after FRAME.\n\
  724. By default, skip minibuffer-only frames.\n\
  725. If omitted, FRAME defaults to the selected frame.\n\
  726. If optional argument MINIFRAME is nil, exclude minibuffer-only frames.\n\
  727. If MINIBUF is a window, include only its own frame\n\
  728. and any frame now using that window as the minibuffer.\n\
  729. If MINIFRAME is `visible', include all visible frames.\n\
  730. If MINIBUF is 0, include all visible and iconified frames.\n\
  731. Otherwise, include all frames.")
  732.   (frame, miniframe)
  733.      Lisp_Object frame, miniframe;
  734. {
  735.   Lisp_Object tail;
  736.  
  737.   if (NILP (frame))
  738.     XSET (frame, Lisp_Frame, selected_frame);
  739.   else
  740.     CHECK_LIVE_FRAME (frame, 0);
  741.  
  742.   return next_frame (frame, miniframe);
  743. }
  744.  
  745. DEFUN ("previous-frame", Fprevious_frame, Sprevious_frame, 0, 2, 0,
  746.   "Return the previous frame in the frame list before FRAME.\n\
  747. By default, skip minibuffer-only frames.\n\
  748. If omitted, FRAME defaults to the selected frame.\n\
  749. If optional argument MINIFRAME is nil, exclude minibuffer-only frames.\n\
  750. If MINIBUF is a window, include only its own frame\n\
  751. and any frame now using that window as the minibuffer.\n\
  752. If MINIFRAME is `visible', include all visible frames.\n\
  753. If MINIBUF is 0, include all visible and iconified frames.\n\
  754. Otherwise, include all frames.")
  755.   (frame, miniframe)
  756.      Lisp_Object frame, miniframe;
  757. {
  758.   Lisp_Object tail;
  759.  
  760.   if (NILP (frame))
  761.     XSET (frame, Lisp_Frame, selected_frame);
  762.   else
  763.     CHECK_LIVE_FRAME (frame, 0);
  764.  
  765.   return prev_frame (frame, miniframe);
  766. }
  767.  
  768. /* Return 1 if it is ok to delete frame F;
  769.    0 if all frames aside from F are invisible.
  770.    (Exception: if F is the terminal frame, and we are using X, return 1.)  */
  771.  
  772. int
  773. other_visible_frames (f)
  774.      FRAME_PTR f;
  775. {
  776.   /* We know the selected frame is visible,
  777.      so if F is some other frame, it can't be the sole visible one.  */
  778.   if (f == selected_frame)
  779.     {
  780.       Lisp_Object frames;
  781.       int count = 0;
  782.  
  783.       for (frames = Vframe_list;
  784.        CONSP (frames);
  785.        frames = XCONS (frames)->cdr)
  786.     {
  787.       Lisp_Object this;
  788.  
  789.       this = XCONS (frames)->car;
  790.       /* Verify that the frame's window still exists
  791.          and we can still talk to it.  And note any recent change
  792.          in visibility.  */
  793. #ifdef HAVE_X_WINDOWS
  794.       if (FRAME_X_P (XFRAME (this)))
  795.         {
  796.           x_sync (this);
  797.           FRAME_SAMPLE_VISIBILITY (XFRAME (this));
  798.         }
  799. #endif
  800.  
  801.       if (FRAME_VISIBLE_P (XFRAME (this))
  802.           || FRAME_ICONIFIED_P (XFRAME (this))
  803.           /* Allow deleting the terminal frame when at least
  804.          one X frame exists!  */
  805.           || (FRAME_X_P (XFRAME (this)) && !FRAME_X_P (f)))
  806.         count++;
  807.     }
  808.       return count > 1;
  809.     }
  810.   return 1;
  811. }
  812.  
  813. DEFUN ("delete-frame", Fdelete_frame, Sdelete_frame, 0, 2, "",
  814.   "Delete FRAME, permanently eliminating it from use.\n\
  815. If omitted, FRAME defaults to the selected frame.\n\
  816. A frame may not be deleted if its minibuffer is used by other frames.\n\
  817. Normally, you may not delete a frame if all other frames are invisible,\n\
  818. but if the second optional argument FORCE is non-nil, you may do so.")
  819.   (frame, force)
  820.      Lisp_Object frame, force;
  821. {
  822.   struct frame *f;
  823.  
  824.   if (EQ (frame, Qnil))
  825.     {
  826.       f = selected_frame;
  827.       XSET (frame, Lisp_Frame, f);
  828.     }
  829.   else
  830.     {
  831.       CHECK_FRAME (frame, 0);
  832.       f = XFRAME (frame);
  833.     }
  834.  
  835.   if (! FRAME_LIVE_P (f))
  836.     return Qnil;
  837.  
  838.   if (NILP (force) && !other_visible_frames (f))
  839.     error ("Attempt to delete the sole visible or iconified frame");
  840.  
  841.   /* Does this frame have a minibuffer, and is it the surrogate
  842.      minibuffer for any other frame?  */
  843.   if (FRAME_HAS_MINIBUF_P (XFRAME (frame)))
  844.     {
  845.       Lisp_Object frames;
  846.  
  847.       for (frames = Vframe_list;
  848.        CONSP (frames);
  849.        frames = XCONS (frames)->cdr)
  850.     {
  851.       Lisp_Object this;
  852.       this = XCONS (frames)->car;
  853.  
  854.       if (! EQ (this, frame)
  855.           && EQ (frame,
  856.              WINDOW_FRAME (XWINDOW
  857.                    (FRAME_MINIBUF_WINDOW (XFRAME (this))))))
  858.         error ("Attempt to delete a surrogate minibuffer frame");
  859.     }
  860.     }
  861.  
  862.   /* Don't let the frame remain selected.  */
  863.   if (f == selected_frame)
  864.     Fhandle_switch_frame (next_frame (frame, Qt), Qnil);
  865.  
  866.   /* Don't allow minibuf_window to remain on a deleted frame.  */
  867.   if (EQ (f->minibuffer_window, minibuf_window))
  868.     {
  869.       Fset_window_buffer (selected_frame->minibuffer_window,
  870.               XWINDOW (minibuf_window)->buffer);
  871.       minibuf_window = selected_frame->minibuffer_window;
  872.     }
  873.  
  874.   /* Clear any X selections for this frame.  */
  875. #ifdef HAVE_X_WINDOWS
  876.   if (FRAME_X_P (f))
  877.     x_clear_frame_selections (f);
  878. #endif
  879.  
  880.   /* Mark all the windows that used to be on FRAME as deleted, and then
  881.      remove the reference to them.  */
  882.   delete_all_subwindows (XWINDOW (f->root_window));
  883.   f->root_window = Qnil;
  884.  
  885.   Vframe_list = Fdelq (frame, Vframe_list);
  886.   FRAME_SET_VISIBLE (f, 0);
  887.  
  888.   if (FRAME_CURRENT_GLYPHS (f))
  889.     free_frame_glyphs (f, FRAME_CURRENT_GLYPHS (f));
  890.   if (FRAME_DESIRED_GLYPHS (f))
  891.     free_frame_glyphs (f, FRAME_DESIRED_GLYPHS (f));
  892.   if (FRAME_TEMP_GLYPHS (f))
  893.     free_frame_glyphs (f, FRAME_TEMP_GLYPHS (f));
  894.   if (FRAME_INSERT_COST (f))
  895.     free (FRAME_INSERT_COST (f));
  896.   if (FRAME_DELETEN_COST (f))
  897.     free (FRAME_DELETEN_COST (f));
  898.   if (FRAME_INSERTN_COST (f))
  899.     free (FRAME_INSERTN_COST (f));
  900.   if (FRAME_DELETE_COST (f))
  901.     free (FRAME_DELETE_COST (f));
  902.  
  903.   /* Since some events are handled at the interrupt level, we may get
  904.      an event for f at any time; if we zero out the frame's display
  905.      now, then we may trip up the event-handling code.  Instead, we'll
  906.      promise that the display of the frame must be valid until we have
  907.      called the window-system-dependent frame destruction routine.  */
  908.  
  909.   /* I think this should be done with a hook.  */
  910. #ifdef HAVE_X_WINDOWS
  911.   if (FRAME_X_P (f))
  912.     x_destroy_window (f);
  913. #endif
  914.  
  915.   f->display.nothing = 0;
  916.  
  917.   /* If we've deleted the last_nonminibuf_frame, then try to find
  918.      another one.  */
  919.   if (f == last_nonminibuf_frame)
  920.     {
  921.       Lisp_Object frames;
  922.  
  923.       last_nonminibuf_frame = 0;
  924.  
  925.       for (frames = Vframe_list;
  926.        CONSP (frames);
  927.        frames = XCONS (frames)->cdr)
  928.     {
  929.       f = XFRAME (XCONS (frames)->car);
  930.       if (!FRAME_MINIBUF_ONLY_P (f))
  931.         {
  932.           last_nonminibuf_frame = f;
  933.           break;
  934.         }
  935.     }
  936.     }
  937.  
  938.   /* If we've deleted Vdefault_minibuffer_frame, try to find another
  939.      one.  Prefer minibuffer-only frames, but also notice frames
  940.      with other windows.  */
  941.   if (EQ (frame, Vdefault_minibuffer_frame))
  942.     {
  943.       Lisp_Object frames;
  944.  
  945.       /* The last frame we saw with a minibuffer, minibuffer-only or not.  */
  946.       Lisp_Object frame_with_minibuf;
  947.  
  948.       frame_with_minibuf = Qnil;
  949.       for (frames = Vframe_list;
  950.        CONSP (frames);
  951.        frames = XCONS (frames)->cdr)
  952.     {
  953.       Lisp_Object this;
  954.  
  955.       this = XCONS (frames)->car;
  956.       if (XTYPE (this) != Lisp_Frame)
  957.         abort ();
  958.       f = XFRAME (this);
  959.  
  960.       if (FRAME_HAS_MINIBUF_P (f))
  961.         {
  962.           frame_with_minibuf = this;
  963.           if (FRAME_MINIBUF_ONLY_P (f))
  964.         break;
  965.         }
  966.     }
  967.  
  968.       /* We know that there must be some frame with a minibuffer out
  969.      there.  If this were not true, all of the frames present
  970.      would have to be minibufferless, which implies that at some
  971.      point their minibuffer frames must have been deleted, but
  972.      that is prohibited at the top; you can't delete surrogate
  973.      minibuffer frames.  */
  974.       if (NILP (frame_with_minibuf))
  975.     abort ();
  976.  
  977.       Vdefault_minibuffer_frame = frame_with_minibuf;
  978.     }
  979.  
  980.   return Qnil;
  981. }
  982.  
  983. /* Return mouse position in character cell units.  */
  984.  
  985. DEFUN ("mouse-position", Fmouse_position, Smouse_position, 0, 0, 0,
  986.   "Return a list (FRAME X . Y) giving the current mouse frame and position.\n\
  987. The position is given in character cells, where (0, 0) is the\n\
  988. upper-left corner.\n\
  989. If Emacs is running on a mouseless terminal or hasn't been programmed\n\
  990. to read the mouse position, it returns the selected frame for FRAME\n\
  991. and nil for X and Y.")
  992.   ()
  993. {
  994.   FRAME_PTR f;
  995.   Lisp_Object lispy_dummy;
  996.   enum scroll_bar_part party_dummy;
  997.   Lisp_Object x, y;
  998.   int col, row;
  999.   unsigned long long_dummy;
  1000.  
  1001.   f = selected_frame;
  1002.   x = y = Qnil;
  1003.  
  1004.   /* It's okay for the hook to refrain from storing anything.  */
  1005.   if (mouse_position_hook)
  1006.     (*mouse_position_hook) (&f,
  1007.                 &lispy_dummy, &party_dummy,
  1008.                 &x, &y,
  1009.                 &long_dummy);
  1010.   if (! NILP (x))
  1011.     {
  1012.       col = XINT (x);
  1013.       row = XINT (y);
  1014.       pixel_to_glyph_coords (f, col, row, &col, &row, 0, 1);
  1015.       XSETINT (x, col);
  1016.       XSETINT (y, row);
  1017.     }
  1018.   XSET (lispy_dummy, Lisp_Frame, f);
  1019.   return Fcons (lispy_dummy, Fcons (x, y));
  1020. }
  1021.  
  1022. DEFUN ("mouse-pixel-position", Fmouse_pixel_position,
  1023.        Smouse_pixel_position, 0, 0, 0,
  1024.   "Return a list (FRAME X . Y) giving the current mouse frame and position.\n\
  1025. The position is given in pixel units, where (0, 0) is the\n\
  1026. upper-left corner.\n\
  1027. If Emacs is running on a mouseless terminal or hasn't been programmed\n\
  1028. to read the mouse position, it returns the selected frame for FRAME\n\
  1029. and nil for X and Y.")
  1030.   ()
  1031. {
  1032.   FRAME_PTR f;
  1033.   Lisp_Object lispy_dummy;
  1034.   enum scroll_bar_part party_dummy;
  1035.   Lisp_Object x, y;
  1036.   int col, row;
  1037.   unsigned long long_dummy;
  1038.  
  1039.   f = selected_frame;
  1040.   x = y = Qnil;
  1041.  
  1042.   /* It's okay for the hook to refrain from storing anything.  */
  1043.   if (mouse_position_hook)
  1044.     (*mouse_position_hook) (&f,
  1045.                 &lispy_dummy, &party_dummy,
  1046.                 &x, &y,
  1047.                 &long_dummy);
  1048.   XSET (lispy_dummy, Lisp_Frame, f);
  1049.   return Fcons (lispy_dummy, Fcons (x, y));
  1050. }
  1051.  
  1052. DEFUN ("set-mouse-position", Fset_mouse_position, Sset_mouse_position, 3, 3, 0,
  1053.   "Move the mouse pointer to the center of character cell (X,Y) in FRAME.\n\
  1054. WARNING:  If you use this under X windows,\n\
  1055. you should call `unfocus-frame' afterwards.")
  1056.   (frame, x, y)
  1057.      Lisp_Object frame, x, y;
  1058. {
  1059.   CHECK_LIVE_FRAME (frame, 0);
  1060.   CHECK_NUMBER (x, 2);
  1061.   CHECK_NUMBER (y, 1);
  1062.  
  1063.   /* I think this should be done with a hook.  */
  1064. #ifdef HAVE_X_WINDOWS
  1065.   if (FRAME_X_P (XFRAME (frame)))
  1066.     /* Warping the mouse will cause  enternotify and focus events. */
  1067.     x_set_mouse_position (XFRAME (frame), x, y);
  1068. #endif
  1069.  
  1070.   return Qnil;
  1071. }
  1072.  
  1073. DEFUN ("set-mouse-pixel-position", Fset_mouse_pixel_position,
  1074.        Sset_mouse_pixel_position, 3, 3, 0,
  1075.   "Move the mouse pointer to pixel position (X,Y) in FRAME.\n\
  1076. WARNING:  If you use this under X windows,\n\
  1077. you should call `unfocus-frame' afterwards.")
  1078.   (frame, x, y)
  1079.      Lisp_Object frame, x, y;
  1080. {
  1081.   CHECK_LIVE_FRAME (frame, 0);
  1082.   CHECK_NUMBER (x, 2);
  1083.   CHECK_NUMBER (y, 1);
  1084.  
  1085.   /* I think this should be done with a hook.  */
  1086. #ifdef HAVE_X_WINDOWS
  1087.   if (FRAME_X_P (XFRAME (frame)))
  1088.     /* Warping the mouse will cause  enternotify and focus events. */
  1089.     x_set_mouse_pixel_position (XFRAME (frame), x, y);
  1090. #endif
  1091.  
  1092.   return Qnil;
  1093. }
  1094. #endif
  1095.  
  1096. #ifdef AMIGA
  1097. DEFUN ("make-frame-visible", Fmake_frame_visible, Smake_frame_visible,
  1098.        0, 1, "",
  1099.   "Make the frame FRAME visible (assuming it is an X-window).\n\
  1100. If omitted, FRAME defaults to the currently selected frame.")
  1101.   (frame)
  1102.      Lisp_Object frame;
  1103. {
  1104. #ifdef MULTI_FRAME
  1105.   if (NILP (frame))
  1106.     XSET (frame, Lisp_Frame, selected_frame);
  1107. #endif
  1108.   
  1109.   CHECK_LIVE_FRAME (frame, 0);
  1110.  
  1111.   /* I think this should be done with a hook.  */
  1112. #if defined(HAVE_X_WINDOWS) || defined(AMIGA)
  1113.   if (FRAME_X_P (XFRAME (frame)))
  1114.     {
  1115.       FRAME_SAMPLE_VISIBILITY (XFRAME (frame));
  1116.       x_make_frame_visible (XFRAME (frame));
  1117.     }
  1118. #endif
  1119.  
  1120.   /* Make menu bar update for the Buffers and Frams menus.  */
  1121.   windows_or_buffers_changed++;
  1122.  
  1123.   return frame;
  1124. }
  1125. #endif
  1126. #ifdef MULTI_FRAME
  1127. DEFUN ("make-frame-invisible", Fmake_frame_invisible, Smake_frame_invisible,
  1128.        0, 2, "",
  1129.   "Make the frame FRAME invisible (assuming it is an X-window).\n\
  1130. If omitted, FRAME defaults to the currently selected frame.\n\
  1131. Normally you may not make FRAME invisible if all other frames are invisible,\n\
  1132. but if the second optional argument FORCE is non-nil, you may do so.")
  1133.   (frame, force)
  1134.      Lisp_Object frame, force;
  1135. {
  1136.   if (NILP (frame))
  1137.     XSET (frame, Lisp_Frame, selected_frame);
  1138.  
  1139.   CHECK_LIVE_FRAME (frame, 0);
  1140.  
  1141.   if (NILP (force) && !other_visible_frames (XFRAME (frame)))
  1142.     error ("Attempt to make invisible the sole visible or iconified frame");
  1143.  
  1144. #if 0 /* This isn't logically necessary, and it can do GC.  */
  1145.   /* Don't let the frame remain selected.  */
  1146.   if (XFRAME (frame) == selected_frame)
  1147.     Fhandle_switch_frame (next_frame (frame, Qt), Qnil);
  1148. #endif
  1149.  
  1150.   /* Don't allow minibuf_window to remain on a deleted frame.  */
  1151.   if (EQ (XFRAME (frame)->minibuffer_window, minibuf_window))
  1152.     {
  1153.       Fset_window_buffer (selected_frame->minibuffer_window,
  1154.               XWINDOW (minibuf_window)->buffer);
  1155.       minibuf_window = selected_frame->minibuffer_window;
  1156.     }
  1157.  
  1158.   /* I think this should be done with a hook.  */
  1159. #ifdef HAVE_X_WINDOWS
  1160.   if (FRAME_X_P (XFRAME (frame)))
  1161.     x_make_frame_invisible (XFRAME (frame));
  1162. #endif
  1163.  
  1164.   /* Make menu bar update for the Buffers and Frams menus.  */
  1165.   windows_or_buffers_changed++;
  1166.  
  1167.   return Qnil;
  1168. }
  1169.  
  1170. DEFUN ("iconify-frame", Ficonify_frame, Siconify_frame,
  1171.        0, 1, "",
  1172.   "Make the frame FRAME into an icon.\n\
  1173. If omitted, FRAME defaults to the currently selected frame.")
  1174.   (frame)
  1175.      Lisp_Object frame;
  1176. {
  1177.   if (NILP (frame))
  1178.     XSET (frame, Lisp_Frame, selected_frame);
  1179.   
  1180.   CHECK_LIVE_FRAME (frame, 0);
  1181.  
  1182. #if 0 /* This isn't logically necessary, and it can do GC.  */
  1183.   /* Don't let the frame remain selected.  */
  1184.   if (XFRAME (frame) == selected_frame)
  1185.     Fhandle_switch_frame (next_frame (frame, Qt), Qnil);
  1186. #endif
  1187.  
  1188.   /* Don't allow minibuf_window to remain on a deleted frame.  */
  1189.   if (EQ (XFRAME (frame)->minibuffer_window, minibuf_window))
  1190.     {
  1191.       Fset_window_buffer (selected_frame->minibuffer_window,
  1192.               XWINDOW (minibuf_window)->buffer);
  1193.       minibuf_window = selected_frame->minibuffer_window;
  1194.     }
  1195.  
  1196.   /* I think this should be done with a hook.  */
  1197. #ifdef HAVE_X_WINDOWS
  1198.   if (FRAME_X_P (XFRAME (frame)))
  1199.       x_iconify_frame (XFRAME (frame));
  1200. #endif
  1201.  
  1202.   /* Make menu bar update for the Buffers and Frams menus.  */
  1203.   windows_or_buffers_changed++;
  1204.  
  1205.   return Qnil;
  1206. }
  1207.  
  1208. DEFUN ("frame-visible-p", Fframe_visible_p, Sframe_visible_p,
  1209.        1, 1, 0,
  1210.        "Return t if FRAME is now \"visible\" (actually in use for display).\n\
  1211. A frame that is not \"visible\" is not updated and, if it works through\n\
  1212. a window system, it may not show at all.\n\
  1213. Return the symbol `icon' if frame is visible only as an icon.")
  1214.   (frame)
  1215.      Lisp_Object frame;
  1216. {
  1217.   CHECK_LIVE_FRAME (frame, 0);
  1218.  
  1219.   FRAME_SAMPLE_VISIBILITY (XFRAME (frame));
  1220.  
  1221.   if (FRAME_VISIBLE_P (XFRAME (frame)))
  1222.     return Qt;
  1223.   if (FRAME_ICONIFIED_P (XFRAME (frame)))
  1224.     return Qicon;
  1225.   return Qnil;
  1226. }
  1227.  
  1228. DEFUN ("visible-frame-list", Fvisible_frame_list, Svisible_frame_list,
  1229.        0, 0, 0,
  1230.        "Return a list of all frames now \"visible\" (being updated).")
  1231.   ()
  1232. {
  1233.   Lisp_Object tail, frame;
  1234.   struct frame *f;
  1235.   Lisp_Object value;
  1236.  
  1237.   value = Qnil;
  1238.   for (tail = Vframe_list; CONSP (tail); tail = XCONS (tail)->cdr)
  1239.     {
  1240.       frame = XCONS (tail)->car;
  1241.       if (XTYPE (frame) != Lisp_Frame)
  1242.     continue;
  1243.       f = XFRAME (frame);
  1244.       if (FRAME_VISIBLE_P (f))
  1245.     value = Fcons (frame, value);
  1246.     }
  1247.   return value;
  1248. }
  1249. #endif
  1250. #ifdef AMIGA
  1251. DEFUN ("raise-frame", Fraise_frame, Sraise_frame, 1, 1, 0,
  1252.   "Bring FRAME to the front, so it occludes any frames it overlaps.\n\
  1253. If FRAME is invisible, make it visible.\n\
  1254. If Emacs is displaying on an ordinary terminal or some other device which\n\
  1255. doesn't support multiple overlapping frames, this function does nothing.")
  1256.   (frame)
  1257.      Lisp_Object frame;
  1258. {
  1259.   CHECK_LIVE_FRAME (frame, 0);
  1260.  
  1261.   /* Do like the documentation says. */
  1262.   Fmake_frame_visible (frame);
  1263.  
  1264.   if (frame_raise_lower_hook)
  1265.     (*frame_raise_lower_hook) (XFRAME (frame), 1);
  1266.  
  1267.   return Qnil;
  1268. }
  1269.  
  1270. /* Should we have a corresponding function called Flower_Power?  */
  1271. DEFUN ("lower-frame", Flower_frame, Slower_frame, 1, 1, 0,
  1272.   "Send FRAME to the back, so it is occluded by any frames that overlap it.\n\
  1273. If Emacs is displaying on an ordinary terminal or some other device which\n\
  1274. doesn't support multiple overlapping frames, this function does nothing.")
  1275.   (frame)
  1276.      Lisp_Object frame;
  1277. {
  1278.   CHECK_LIVE_FRAME (frame, 0);
  1279.   
  1280.   if (frame_raise_lower_hook)
  1281.     (*frame_raise_lower_hook) (XFRAME (frame), 0);
  1282.  
  1283.   return Qnil;
  1284. }
  1285. #ifdef MULTI_FRAME
  1286.  
  1287. DEFUN ("redirect-frame-focus", Fredirect_frame_focus, Sredirect_frame_focus,
  1288.        1, 2, 0,
  1289.   "Arrange for keystrokes typed at FRAME to be sent to FOCUS-FRAME.\n\
  1290. In other words, switch-frame events caused by events in FRAME will\n\
  1291. request a switch to FOCUS-FRAME, and `last-event-frame' will be\n\
  1292. FOCUS-FRAME after reading an event typed at FRAME.\n\
  1293. \n\
  1294. If FOCUS-FRAME is omitted or nil, any existing redirection is\n\
  1295. cancelled, and the frame again receives its own keystrokes.\n\
  1296. \n\
  1297. Focus redirection is useful for temporarily redirecting keystrokes to\n\
  1298. a surrogate minibuffer frame when a frame doesn't have its own\n\
  1299. minibuffer window.\n\
  1300. \n\
  1301. A frame's focus redirection can be changed by select-frame.  If frame\n\
  1302. FOO is selected, and then a different frame BAR is selected, any\n\
  1303. frames redirecting their focus to FOO are shifted to redirect their\n\
  1304. focus to BAR.  This allows focus redirection to work properly when the\n\
  1305. user switches from one frame to another using `select-window'.\n\
  1306. \n\
  1307. This means that a frame whose focus is redirected to itself is treated\n\
  1308. differently from a frame whose focus is redirected to nil; the former\n\
  1309. is affected by select-frame, while the latter is not.\n\
  1310. \n\
  1311. The redirection lasts until `redirect-frame-focus' is called to change it.")
  1312.   (frame, focus_frame)
  1313.     Lisp_Object frame, focus_frame;
  1314. {
  1315.   /* Note that we don't check for a live frame here.  It's reasonable
  1316.      to redirect the focus of a frame you're about to delete, if you
  1317.      know what other frame should receive those keystrokes.  */
  1318.   CHECK_FRAME (frame, 0);
  1319.  
  1320.   if (! NILP (focus_frame))
  1321.     CHECK_LIVE_FRAME (focus_frame, 1);
  1322.  
  1323.   XFRAME (frame)->focus_frame = focus_frame;
  1324.  
  1325.   /* I think this should be done with a hook.  */
  1326. #ifdef HAVE_X_WINDOWS
  1327.   if (!NILP (focus_frame) && ! EQ (focus_frame, frame)
  1328.       && FRAME_X_P (XFRAME (focus_frame)))
  1329.     Ffocus_frame (focus_frame);
  1330. #endif
  1331.  
  1332.   if (frame_rehighlight_hook)
  1333.     (*frame_rehighlight_hook) ();
  1334.   
  1335.   return Qnil;
  1336. }
  1337.  
  1338.  
  1339. DEFUN ("frame-focus", Fframe_focus, Sframe_focus, 1, 1, 0,
  1340.   "Return the frame to which FRAME's keystrokes are currently being sent.\n\
  1341. This returns nil if FRAME's focus is not redirected.\n\
  1342. See `redirect-frame-focus'.")
  1343.   (frame)
  1344.     Lisp_Object frame;
  1345. {
  1346.   CHECK_LIVE_FRAME (frame, 0);
  1347.  
  1348.   return FRAME_FOCUS_FRAME (XFRAME (frame));
  1349. }
  1350.  
  1351.  
  1352.  
  1353. #endif
  1354. #ifdef AMIGA
  1355. void
  1356. store_in_alist (alistptr, prop, val)
  1357.      Lisp_Object *alistptr, val;
  1358.      Lisp_Object prop;
  1359. {
  1360.   register Lisp_Object tem;
  1361.  
  1362.   tem = Fassq (prop, *alistptr);
  1363.   if (EQ (tem, Qnil))
  1364.     *alistptr = Fcons (Fcons (prop, val), *alistptr);
  1365.   else
  1366.     Fsetcdr (tem, val);
  1367. }
  1368. #endif
  1369. #ifdef AMIGA /* CHFIXME */
  1370. #ifndef MULTI_FRAME
  1371. #ifdef USE_EXTERNAL_MENU_BAR
  1372. Lisp_Object the_only_param_alist; /* can\'t store it in the_only_window, it\'s collectile */
  1373. Lisp_Object the_only_menu_bar_items; /* can\'t store it in the_only_window, it\'s collectile */
  1374. Lisp_Object the_only_menu_bar_vector; /* can\'t store it in the_only_window, it\'s collectile */
  1375. #endif
  1376. #ifdef USE_SCROLL_BARS
  1377. Lisp_Object the_only_scroll_bars;
  1378. Lisp_Object the_only_condemned_scroll_bars;
  1379. #endif
  1380. #endif
  1381. Lisp_Object
  1382. get_frame_param (frame, prop)
  1383.      FRAME_PTR frame;
  1384.      Lisp_Object prop;
  1385. {
  1386.   register Lisp_Object tem;
  1387.  
  1388.   tem = Fassq (prop, FRAME_PARAM_ALIST(f));
  1389.   if (EQ (tem, Qnil))
  1390.     return tem;
  1391.   return Fcdr (tem);
  1392. }
  1393.  
  1394. extern Lisp_Object Qminibuffer; /* comes at end of this file CHFIXME */
  1395.  
  1396. void
  1397. store_frame_param (f, prop, val)
  1398.      FRAME_PTR f;
  1399.      Lisp_Object prop, val;
  1400. {
  1401.   register Lisp_Object tem;
  1402.  
  1403.   tem = Fassq (prop, FRAME_PARAM_ALIST(f));
  1404.   if (EQ (tem, Qnil))
  1405.     FRAME_PARAM_ALIST(f) = Fcons (Fcons (prop, val), FRAME_PARAM_ALIST(f));
  1406.   else
  1407.     Fsetcdr (tem, val);
  1408.  
  1409. #ifndef AMIGA /* CHFIXME meaning ? */
  1410.   if (EQ (prop, Qminibuffer)
  1411.       && XTYPE (val) == Lisp_Window)
  1412.     {
  1413.       if (! MINI_WINDOW_P (XWINDOW (val)))
  1414.     error ("Surrogate minibuffer windows must be minibuffer windows.");
  1415.  
  1416.       if (FRAME_HAS_MINIBUF_P (f) || FRAME_MINIBUF_ONLY_P (f))
  1417.     error ("can't change the surrogate minibuffer of a frame with its own minibuffer");
  1418.  
  1419.       /* Install the chosen minibuffer window, with proper buffer.  */
  1420.       FRAME_MINIBUF_WINDOW(W) = val;
  1421.     }
  1422. #endif
  1423. }
  1424. #endif /* AMIGA */
  1425.  
  1426. #ifdef AMIGA
  1427. /* CHFIXME: defined below */
  1428.  
  1429. extern Lisp_Object Qname;
  1430. extern Lisp_Object Qheight;
  1431. extern Lisp_Object Qwidth;
  1432. extern Lisp_Object Qmodeline;
  1433. extern Lisp_Object Qminibuffer;
  1434. extern Lisp_Object Qunsplittable;
  1435. extern Lisp_Object Qmenu_bar_lines;
  1436.  
  1437. DEFUN ("frame-parameters", Fframe_parameters, Sframe_parameters, 0, 1, 0,
  1438.   "Return the parameters-alist of frame FRAME.\n\
  1439. It is a list of elements of the form (PARM . VALUE), where PARM is a symbol.\n\
  1440. The meaningful PARMs depend on the kind of frame.\n\
  1441. If FRAME is omitted, return information on the currently selected frame.")
  1442.   (frame)
  1443.      Lisp_Object frame;
  1444. {
  1445.   Lisp_Object alist;
  1446.   FRAME_PTR f;
  1447.  
  1448.   if (EQ (frame, Qnil))
  1449.     f = selected_frame;
  1450.   else
  1451.     {
  1452.       CHECK_FRAME (frame, 0);
  1453.       f = XFRAME (frame);
  1454.     }
  1455.  
  1456.   if (!FRAME_LIVE_P (f))
  1457.     return Qnil;
  1458.  
  1459.   alist = Fcopy_alist (FRAME_PARAM_ALIST(f));
  1460.  
  1461. #ifdef AMIGA /* CHFIXME */
  1462.   store_in_alist (&alist, Qname, build_string ("emacs"));
  1463. #else
  1464.   store_in_alist (&alist, Qname, f->name);
  1465. #endif
  1466.   store_in_alist (&alist, Qheight, make_number (FRAME_HEIGHT (f)));
  1467.   store_in_alist (&alist, Qwidth, make_number (FRAME_WIDTH (f)));
  1468.   store_in_alist (&alist, Qmodeline, (FRAME_WANTS_MODELINE_P (f) ? Qt : Qnil));
  1469.   store_in_alist (&alist, Qminibuffer,
  1470.           (! FRAME_HAS_MINIBUF_P (f) ? Qnil
  1471. #ifndef AMIGA /* CHFIXME: meaning? */
  1472.            : FRAME_MINIBUF_ONLY_P (f) ? Qonly
  1473. #endif
  1474.            : FRAME_MINIBUF_WINDOW (f)));
  1475.   store_in_alist (&alist, Qunsplittable, (FRAME_NO_SPLIT_P (f) ? Qt : Qnil));
  1476.  
  1477.   /* I think this should be done with a hook.  */
  1478. #ifdef HAVE_X_WINDOWS
  1479.   if (FRAME_X_P (f))
  1480.     x_report_frame_params (f, &alist);
  1481.   else
  1482. #endif
  1483.     /* This ought to be correct in f->param_alist for an X frame.  */
  1484.     store_in_alist (&alist, Qmenu_bar_lines, FRAME_MENU_BAR_LINES (f));
  1485. #ifdef AMIGA /* CHFIXME */
  1486.   {
  1487.     if (EMACS_WIN(f))
  1488.     x_report_frame_params (f, &alist);
  1489.   }
  1490. #endif
  1491.   return alist;
  1492. }
  1493. #endif
  1494. #ifdef AMIGA
  1495. DEFUN ("modify-frame-parameters", Fmodify_frame_parameters, 
  1496.        Smodify_frame_parameters, 2, 2, 0,
  1497.   "Modify the parameters of frame FRAME according to ALIST.\n\
  1498. ALIST is an alist of parameters to change and their new values.\n\
  1499. Each element of ALIST has the form (PARM . VALUE), where PARM is a symbol.\n\
  1500. The meaningful PARMs depend on the kind of frame; undefined PARMs are ignored.")
  1501.   (frame, alist)
  1502.      Lisp_Object frame, alist;
  1503. {
  1504.   FRAME_PTR f;
  1505.   register Lisp_Object tail, elt, prop, val;
  1506.  
  1507.   if (EQ (frame, Qnil))
  1508.     f = selected_frame;
  1509.   else
  1510.     {
  1511.       CHECK_LIVE_FRAME (frame, 0);
  1512.       f = XFRAME (frame);
  1513.     }
  1514.  
  1515.   /* I think this should be done with a hook.  */
  1516. #ifdef HAVE_X_WINDOWS
  1517.   if (FRAME_X_P (f))
  1518. #if 1
  1519.     x_set_frame_parameters (f, alist);
  1520. #else
  1521.     for (tail = alist; !EQ (tail, Qnil); tail = Fcdr (tail))
  1522.       {
  1523.     elt = Fcar (tail);
  1524.     prop = Fcar (elt);
  1525.     val = Fcdr (elt);
  1526.     x_set_frame_param (f, prop, val, get_frame_param (f, prop));
  1527.     store_frame_param (f, prop, val);
  1528.       }
  1529. #endif
  1530. #endif
  1531.  
  1532. #ifdef AMIGA /* CHFIXME */
  1533.   {
  1534.     if (EMACS_WIN(f))
  1535.       x_set_frame_parameters (f, alist);
  1536.   }
  1537. #endif
  1538.  
  1539.   return Qnil;
  1540. }
  1541. #endif /* AMIGA */
  1542.  
  1543. #ifdef MULTI_FRAME
  1544. DEFUN ("frame-char-height", Fframe_char_height, Sframe_char_height,
  1545.   0, 1, 0,
  1546.   "Height in pixels of a line in the font in frame FRAME.\n\
  1547. If FRAME is omitted, the selected frame is used.\n\
  1548. For a terminal frame, the value is always 1.")
  1549.   (frame)
  1550.      Lisp_Object frame;
  1551. {
  1552.   struct frame *f;
  1553.  
  1554.   if (NILP (frame))
  1555.     f = selected_frame;
  1556.   else
  1557.     {
  1558.       CHECK_FRAME (frame, 0);
  1559.       f = XFRAME (frame);
  1560.     }
  1561.  
  1562. #ifdef HAVE_X_WINDOWS
  1563.   if (FRAME_X_P (f))
  1564.     return make_number (x_char_height (f));
  1565.   else
  1566. #endif
  1567.     return make_number (1);
  1568. }
  1569.  
  1570.  
  1571. DEFUN ("frame-char-width", Fframe_char_width, Sframe_char_width,
  1572.   0, 1, 0,
  1573.   "Width in pixels of characters in the font in frame FRAME.\n\
  1574. If FRAME is omitted, the selected frame is used.\n\
  1575. The width is the same for all characters, because\n\
  1576. currently Emacs supports only fixed-width fonts.\n\
  1577. For a terminal screen, the value is always 1.")
  1578.   (frame)
  1579.      Lisp_Object frame;
  1580. {
  1581.   struct frame *f;
  1582.  
  1583.   if (NILP (frame))
  1584.     f = selected_frame;
  1585.   else
  1586.     {
  1587.       CHECK_FRAME (frame, 0);
  1588.       f = XFRAME (frame);
  1589.     }
  1590.  
  1591. #ifdef HAVE_X_WINDOWS
  1592.   if (FRAME_X_P (f))
  1593.     return make_number (x_char_width (f));
  1594.   else
  1595. #endif
  1596.     return make_number (1);
  1597. }
  1598.  
  1599. DEFUN ("frame-pixel-height", Fframe_pixel_height, 
  1600.        Sframe_pixel_height, 0, 1, 0,
  1601.   "Return a FRAME's height in pixels.\n\
  1602. For a terminal frame, the result really gives the height in characters.\n\
  1603. If FRAME is omitted, the selected frame is used.")
  1604.   (frame)
  1605.      Lisp_Object frame;
  1606. {
  1607.   struct frame *f;
  1608.  
  1609.   if (NILP (frame))
  1610.     f = selected_frame;
  1611.   else
  1612.     {
  1613.       CHECK_FRAME (frame, 0);
  1614.       f = XFRAME (frame);
  1615.     }
  1616.  
  1617. #ifdef HAVE_X_WINDOWS
  1618.   if (FRAME_X_P (f))
  1619.     return make_number (x_pixel_height (f));
  1620.   else
  1621. #endif
  1622.     return make_number (FRAME_HEIGHT (f));
  1623. }
  1624.  
  1625. DEFUN ("frame-pixel-width", Fframe_pixel_width, 
  1626.        Sframe_pixel_width, 0, 1, 0,
  1627.   "Return FRAME's width in pixels.\n\
  1628. For a terminal frame, the result really gives the width in characters.\n\
  1629. If FRAME is omitted, the selected frame is used.")
  1630.   (frame)
  1631.      Lisp_Object frame;
  1632. {
  1633.   struct frame *f;
  1634.  
  1635.   if (NILP (frame))
  1636.     f = selected_frame;
  1637.   else
  1638.     {
  1639.       CHECK_FRAME (frame, 0);
  1640.       f = XFRAME (frame);
  1641.     }
  1642.  
  1643. #ifdef HAVE_X_WINDOWS
  1644.   if (FRAME_X_P (f))
  1645.     return make_number (x_pixel_width (f));
  1646.   else
  1647. #endif
  1648.     return make_number (FRAME_WIDTH (f));
  1649. }
  1650.  
  1651. DEFUN ("set-frame-height", Fset_frame_height, Sset_frame_height, 2, 3, 0,
  1652.   "Specify that the frame FRAME has LINES lines.\n\
  1653. Optional third arg non-nil means that redisplay should use LINES lines\n\
  1654. but that the idea of the actual height of the frame should not be changed.")
  1655.   (frame, rows, pretend)
  1656.      Lisp_Object frame, rows, pretend;
  1657. {
  1658.   register struct frame *f;
  1659.  
  1660.   CHECK_NUMBER (rows, 0);
  1661.   if (NILP (frame))
  1662.     f = selected_frame;
  1663.   else
  1664.     {
  1665.       CHECK_LIVE_FRAME (frame, 0);
  1666.       f = XFRAME (frame);
  1667.     }
  1668.  
  1669.   /* I think this should be done with a hook.  */
  1670. #ifdef HAVE_X_WINDOWS
  1671.   if (FRAME_X_P (f))
  1672.     {
  1673.       if (XINT (rows) != f->width)
  1674.     x_set_window_size (f, 1, f->width, XINT (rows));
  1675.     }
  1676.   else
  1677. #endif
  1678.     change_frame_size (f, XINT (rows), 0, !NILP (pretend), 0);
  1679.   return Qnil;
  1680. }
  1681.  
  1682. DEFUN ("set-frame-width", Fset_frame_width, Sset_frame_width, 2, 3, 0,
  1683.   "Specify that the frame FRAME has COLS columns.\n\
  1684. Optional third arg non-nil means that redisplay should use COLS columns\n\
  1685. but that the idea of the actual width of the frame should not be changed.")
  1686.   (frame, cols, pretend)
  1687.      Lisp_Object frame, cols, pretend;
  1688. {
  1689.   register struct frame *f;
  1690.   CHECK_NUMBER (cols, 0);
  1691.   if (NILP (frame))
  1692.     f = selected_frame;
  1693.   else
  1694.     {
  1695.       CHECK_LIVE_FRAME (frame, 0);
  1696.       f = XFRAME (frame);
  1697.     }
  1698.  
  1699.   /* I think this should be done with a hook.  */
  1700. #ifdef HAVE_X_WINDOWS
  1701.   if (FRAME_X_P (f))
  1702.     {
  1703.       if (XINT (cols) != f->width)
  1704.     x_set_window_size (f, 1, XINT (cols), f->height);
  1705.     }
  1706.   else
  1707. #endif
  1708.     change_frame_size (f, 0, XINT (cols), !NILP (pretend), 0);
  1709.   return Qnil;
  1710. }
  1711.  
  1712. DEFUN ("set-frame-size", Fset_frame_size, Sset_frame_size, 3, 3, 0,
  1713.   "Sets size of FRAME to COLS by ROWS, measured in characters.")
  1714.   (frame, cols, rows)
  1715.      Lisp_Object frame, cols, rows;
  1716. {
  1717.   register struct frame *f;
  1718.   int mask;
  1719.  
  1720.   CHECK_LIVE_FRAME (frame, 0);
  1721.   CHECK_NUMBER (cols, 2);
  1722.   CHECK_NUMBER (rows, 1);
  1723.   f = XFRAME (frame);
  1724.  
  1725.   /* I think this should be done with a hook.  */
  1726. #ifdef HAVE_X_WINDOWS
  1727.   if (FRAME_X_P (f))
  1728.     {
  1729.       if (XINT (rows) != f->height || XINT (cols) != f->width)
  1730.     x_set_window_size (f, 1, XINT (cols), XINT (rows));
  1731.     }
  1732.   else
  1733. #endif
  1734.     change_frame_size (f, XINT (rows), XINT (cols), 0, 0);
  1735.  
  1736.   return Qnil;
  1737. }
  1738.  
  1739. DEFUN ("set-frame-position", Fset_frame_position, 
  1740.        Sset_frame_position, 3, 3, 0,
  1741.   "Sets position of FRAME in pixels to XOFFSET by YOFFSET.\n\
  1742. This is actually the position of the upper left corner of the frame.\n\
  1743. Negative values for XOFFSET or YOFFSET are interpreted relative to\n\
  1744. the rightmost or bottommost possible position (that stays within the screen).")
  1745.   (frame, xoffset, yoffset)
  1746.      Lisp_Object frame, xoffset, yoffset;
  1747. {
  1748.   register struct frame *f;
  1749.   int mask;
  1750.  
  1751.   CHECK_LIVE_FRAME (frame, 0);
  1752.   CHECK_NUMBER (xoffset, 1);
  1753.   CHECK_NUMBER (yoffset, 2);
  1754.   f = XFRAME (frame);
  1755.  
  1756.   /* I think this should be done with a hook.  */
  1757. #ifdef HAVE_X_WINDOWS
  1758.   if (FRAME_X_P (f))
  1759.     x_set_offset (f, XINT (xoffset), XINT (yoffset), 1);
  1760. #endif
  1761.  
  1762.   return Qt;
  1763. }
  1764.  
  1765.  
  1766. choose_minibuf_frame ()
  1767. {
  1768.   /* For lowest-level minibuf, put it on currently selected frame
  1769.      if frame has a minibuffer.  */
  1770.  
  1771.   if (minibuf_level == 0
  1772.       && selected_frame != 0
  1773.       && !EQ (minibuf_window, selected_frame->minibuffer_window))
  1774.     {
  1775.       /* I don't think that any frames may validly have a null minibuffer
  1776.      window anymore.  */
  1777.       if (NILP (selected_frame->minibuffer_window))
  1778.     abort ();
  1779.  
  1780.       Fset_window_buffer (selected_frame->minibuffer_window,
  1781.               XWINDOW (minibuf_window)->buffer);
  1782.       minibuf_window = selected_frame->minibuffer_window;
  1783.     }
  1784. }
  1785.  
  1786. syms_of_frame ()
  1787. {
  1788.   /*&&& init symbols here &&&*/
  1789.   Qframep = intern ("framep");
  1790.   staticpro (&Qframep);
  1791.   Qframe_live_p = intern ("frame-live-p");
  1792.   staticpro (&Qframe_live_p);
  1793.   Qheight = intern ("height");
  1794.   staticpro (&Qheight);
  1795.   Qicon = intern ("icon");
  1796.   staticpro (&Qicon);
  1797.   Qminibuffer = intern ("minibuffer");
  1798.   staticpro (&Qminibuffer);
  1799.   Qmodeline = intern ("modeline");
  1800.   staticpro (&Qmodeline);
  1801.   Qname = intern ("name");
  1802.   staticpro (&Qname);
  1803.   Qonly = intern ("only");
  1804.   staticpro (&Qonly);
  1805.   Qunsplittable = intern ("unsplittable");
  1806.   staticpro (&Qunsplittable);
  1807.   Qmenu_bar_lines = intern ("menu-bar-lines");
  1808.   staticpro (&Qmenu_bar_lines);
  1809.   Qwidth = intern ("width");
  1810.   staticpro (&Qwidth);
  1811.   Qx = intern ("x");
  1812.   staticpro (&Qx);
  1813.   Qvisible = intern ("visible");
  1814.   staticpro (&Qvisible);
  1815.  
  1816.   staticpro (&Vframe_list);
  1817.  
  1818.   DEFVAR_LISP ("terminal-frame", &Vterminal_frame,
  1819.     "The initial frame-object, which represents Emacs's stdout.");
  1820.  
  1821.   DEFVAR_LISP ("emacs-iconified", &Vemacs_iconified,
  1822.     "Non-nil if all of emacs is iconified and frame updates are not needed.");
  1823.   Vemacs_iconified = Qnil;
  1824.  
  1825.   DEFVAR_LISP ("default-minibuffer-frame", &Vdefault_minibuffer_frame,
  1826.     "Minibufferless frames use this frame's minibuffer.\n\
  1827. \n\
  1828. Emacs cannot create minibufferless frames unless this is set to an\n\
  1829. appropriate surrogate.\n\
  1830. \n\
  1831. Emacs consults this variable only when creating minibufferless\n\
  1832. frames; once the frame is created, it sticks with its assigned\n\
  1833. minibuffer, no matter what this variable is set to.  This means that\n\
  1834. this variable doesn't necessarily say anything meaningful about the\n\
  1835. current set of frames, or where the minibuffer is currently being\n\
  1836. displayed.");
  1837.   Vdefault_minibuffer_frame = Qnil;
  1838.  
  1839.   DEFVAR_LISP ("default-frame-alist", &Vdefault_frame_alist,
  1840.     "Alist of default values for frame creation.\n\
  1841. These may be set in your init file, like this:\n\
  1842.   (setq default-frame-alist '((width . 80) (height . 55)))\n\
  1843. These override values given in window system configuration data, like\n\
  1844. X Windows' defaults database.\n\
  1845. For values specific to the first Emacs frame, see `initial-frame-alist'.\n\
  1846. For values specific to the separate minibuffer frame, see\n\
  1847. `minibuffer-frame-alist'.");
  1848.   Vdefault_frame_alist = Qnil;
  1849.  
  1850.   defsubr (&Sframep);
  1851.   defsubr (&Sframe_live_p);
  1852.   defsubr (&Shandle_switch_frame);
  1853.   defsubr (&Sselect_frame);
  1854.   defsubr (&Sselected_frame);
  1855.   defsubr (&Swindow_frame);
  1856.   defsubr (&Sframe_root_window);
  1857.   defsubr (&Sframe_first_window);
  1858.   defsubr (&Sframe_selected_window);
  1859.   defsubr (&Sset_frame_selected_window);
  1860.   defsubr (&Sframe_list);
  1861.   defsubr (&Snext_frame);
  1862.   defsubr (&Sprevious_frame);
  1863.   defsubr (&Sdelete_frame);
  1864.   defsubr (&Smouse_position);
  1865.   defsubr (&Smouse_pixel_position);
  1866.   defsubr (&Sset_mouse_position);
  1867.   defsubr (&Sset_mouse_pixel_position);
  1868. #if 0
  1869.   defsubr (&Sframe_configuration);
  1870.   defsubr (&Srestore_frame_configuration);
  1871. #endif
  1872.   defsubr (&Smake_frame_visible);
  1873.   defsubr (&Smake_frame_invisible);
  1874.   defsubr (&Siconify_frame);
  1875.   defsubr (&Sframe_visible_p);
  1876.   defsubr (&Svisible_frame_list);
  1877.   defsubr (&Sraise_frame);
  1878.   defsubr (&Slower_frame);
  1879.   defsubr (&Sredirect_frame_focus);
  1880.   defsubr (&Sframe_focus);
  1881.   defsubr (&Sframe_parameters);
  1882.   defsubr (&Smodify_frame_parameters);
  1883.   defsubr (&Sframe_char_height);
  1884.   defsubr (&Sframe_char_width);
  1885.   defsubr (&Sframe_pixel_height);
  1886.   defsubr (&Sframe_pixel_width);
  1887.   defsubr (&Sset_frame_height);
  1888.   defsubr (&Sset_frame_width);
  1889.   defsubr (&Sset_frame_size);
  1890.   defsubr (&Sset_frame_position);
  1891. }
  1892.  
  1893. keys_of_frame ()
  1894. {
  1895.   initial_define_lispy_key (global_map, "switch-frame", "handle-switch-frame");
  1896. }
  1897.  
  1898. #else /* not MULTI_FRAME */
  1899.  
  1900. /* If we're not using multi-frame stuff, we still need to provide some
  1901.    support functions.  */
  1902.  
  1903. Lisp_Object Qheight;
  1904. Lisp_Object Qminibuffer;
  1905. Lisp_Object Qmodeline;
  1906. Lisp_Object Qname;
  1907. Lisp_Object Qunsplittable;
  1908. Lisp_Object Qmenu_bar_lines;
  1909. Lisp_Object Qwidth;
  1910.  
  1911. Lisp_Object Vterminal_frame;
  1912. #ifdef AMIGA
  1913. Lisp_Object Vdefault_frame_alist;
  1914. #endif
  1915.  
  1916. /* Unless this function is defined, providing set-frame-height and
  1917.    set-frame-width doesn't help compatibility any, since they both
  1918.    want this as their first argument.  */
  1919. DEFUN ("selected-frame", Fselected_frame, Sselected_frame, 0, 0, 0,
  1920.   /* Don't confuse make-docfile by having two doc strings for this function.
  1921.      make-docfile does not pay attention to #if, for good reason!  */
  1922.   0)
  1923.   ()
  1924. {
  1925.   Lisp_Object tem;
  1926.   XFASTINT (tem) = 0;
  1927.   return tem;
  1928. }
  1929.  
  1930. DEFUN ("frame-first-window", Fframe_first_window, Sframe_first_window, 0, 1, 0,
  1931.   0)
  1932.   (frame)
  1933.      Lisp_Object frame;
  1934. {
  1935.   Lisp_Object w;
  1936.  
  1937.   w = FRAME_ROOT_WINDOW (selected_frame);
  1938.  
  1939.   while (NILP (XWINDOW (w)->buffer))
  1940.     {
  1941.       if (! NILP (XWINDOW (w)->hchild))
  1942.     w = XWINDOW (w)->hchild;
  1943.       else if (! NILP (XWINDOW (w)->vchild))
  1944.     w = XWINDOW (w)->vchild;
  1945.       else
  1946.     abort ();
  1947.     }
  1948.   return w;
  1949. }
  1950.  
  1951. DEFUN ("framep", Fframep, Sframep, 1, 1, 0,
  1952.   /* Don't confuse make-docfile by having two doc strings for this function.
  1953.      make-docfile does not pay attention to #if, for good reason!  */
  1954.   0)
  1955.   (object)
  1956.      Lisp_Object object;
  1957. {
  1958.   return Qnil;
  1959. }
  1960.  
  1961. DEFUN ("set-frame-height", Fset_frame_height, Sset_frame_height, 2, 3, 0,
  1962.   /* Don't confuse make-docfile by having two doc strings for this function.
  1963.      make-docfile does not pay attention to #if, for good reason!  */
  1964.   0)
  1965.   (frame, rows, pretend)
  1966.      Lisp_Object frame, rows, pretend;
  1967. {
  1968.   CHECK_NUMBER (rows, 0);
  1969.  
  1970.   change_frame_size (0, XINT (rows), 0, !NILP (pretend), 0);
  1971.   return Qnil;
  1972. }
  1973.  
  1974. DEFUN ("set-frame-width", Fset_frame_width, Sset_frame_width, 2, 3, 0,
  1975.   /* Don't confuse make-docfile by having two doc strings for this function.
  1976.      make-docfile does not pay attention to #if, for good reason!  */
  1977.   0)
  1978.   (frame, cols, pretend)
  1979.      Lisp_Object frame, cols, pretend;
  1980. {
  1981.   CHECK_NUMBER (cols, 0);
  1982.  
  1983.   change_frame_size (0, 0, XINT (cols), !NILP (pretend), 0);
  1984.   return Qnil;
  1985. }
  1986.  
  1987. DEFUN ("set-frame-size", Fset_frame_size, Sset_frame_size, 3, 3, 0,
  1988.   /* Don't confuse make-docfile by having two doc strings for this function.
  1989.      make-docfile does not pay attention to #if, for good reason!  */
  1990.   0)
  1991.   (frame, cols, rows)
  1992.      Lisp_Object frame, cols, rows;
  1993. {
  1994.   CHECK_NUMBER (cols, 2);
  1995.   CHECK_NUMBER (rows, 1);
  1996.  
  1997.   change_frame_size (0, XINT (rows), XINT (cols), 0, 0);
  1998.  
  1999.   return Qnil;
  2000. }
  2001.  
  2002. DEFUN ("frame-height", Fframe_height, Sframe_height, 0, 1, 0,
  2003.   "Return number of lines available for display on FRAME.\n\
  2004. If FRAME is omitted, describe the currently selected frame.")
  2005.   (frame)
  2006.     Lisp_Object frame;
  2007. {
  2008.   return make_number (FRAME_HEIGHT (selected_frame));
  2009. }
  2010.  
  2011. DEFUN ("frame-width", Fframe_width, Sframe_width, 0, 1, 0,
  2012.   "Return number of columns available for display on FRAME.\n\
  2013. If FRAME is omitted, describe the currently selected frame.")
  2014.   (frame)
  2015.     Lisp_Object frame;
  2016. {
  2017.   return make_number (FRAME_WIDTH (selected_frame));
  2018. }
  2019.  
  2020. DEFUN ("frame-char-height", Fframe_char_height, Sframe_char_height,
  2021.   0, 1, 0,
  2022.   /* Don't confuse make-docfile by having two doc strings for this function.
  2023.      make-docfile does not pay attention to #if, for good reason!  */
  2024.   0)
  2025.   (frame)
  2026.      Lisp_Object frame;
  2027. {
  2028.   return make_number (1);
  2029. }
  2030.  
  2031.  
  2032. DEFUN ("frame-char-width", Fframe_char_width, Sframe_char_width,
  2033.   0, 1, 0,
  2034.   /* Don't confuse make-docfile by having two doc strings for this function.
  2035.      make-docfile does not pay attention to #if, for good reason!  */
  2036.   0)
  2037.   (frame)
  2038.      Lisp_Object frame;
  2039. {
  2040.   return make_number (1);
  2041. }
  2042.  
  2043. DEFUN ("frame-pixel-height", Fframe_pixel_height, 
  2044.        Sframe_pixel_height, 0, 1, 0,
  2045.   /* Don't confuse make-docfile by having two doc strings for this function.
  2046.      make-docfile does not pay attention to #if, for good reason!  */
  2047.   0)
  2048.   (frame)
  2049.      Lisp_Object frame;
  2050. {
  2051.   return make_number (FRAME_HEIGHT (f));
  2052. }
  2053.  
  2054. DEFUN ("frame-pixel-width", Fframe_pixel_width, 
  2055.        Sframe_pixel_width, 0, 1, 0,
  2056.   /* Don't confuse make-docfile by having two doc strings for this function.
  2057.      make-docfile does not pay attention to #if, for good reason!  */
  2058.   0)
  2059.   (frame)
  2060.      Lisp_Object frame;
  2061. {
  2062.   return make_number (FRAME_WIDTH (f));
  2063. }
  2064.  
  2065. /* These are for backward compatibility with Emacs 18.  */
  2066.  
  2067. DEFUN ("set-screen-height", Fset_screen_height, Sset_screen_height, 1, 2, 0,
  2068.   "Tell redisplay that the screen has LINES lines.\n\
  2069. Optional second arg non-nil means that redisplay should use LINES lines\n\
  2070. but that the idea of the actual height of the screen should not be changed.")
  2071.   (lines, pretend)
  2072.      Lisp_Object lines, pretend;
  2073. {
  2074.   CHECK_NUMBER (lines, 0);
  2075.  
  2076.   change_frame_size (0, XINT (lines), 0, !NILP (pretend), 0);
  2077.   return Qnil;
  2078. }
  2079.  
  2080. DEFUN ("set-screen-width", Fset_screen_width, Sset_screen_width, 1, 2, 0,
  2081.   "Tell redisplay that the screen has COLS columns.\n\
  2082. Optional second arg non-nil means that redisplay should use COLS columns\n\
  2083. but that the idea of the actual width of the screen should not be changed.")
  2084.   (cols, pretend)
  2085.      Lisp_Object cols, pretend;
  2086. {
  2087.   CHECK_NUMBER (cols, 0);
  2088.  
  2089.   change_frame_size (0, 0, XINT (cols), !NILP (pretend), 0);
  2090.   return Qnil;
  2091. }
  2092.  
  2093. DEFUN ("mouse-position", Fmouse_position, Smouse_position, 0, 0, 0,
  2094.   /* Don't confuse make-docfile by having two doc strings for this function.
  2095.      make-docfile does not pay attention to #if, for good reason!  */
  2096.   0)
  2097.   ()
  2098. #ifndef HAVE_MOUSE
  2099. {
  2100.   return Fcons (Qnil, Fcons (Qnil, Qnil));
  2101. }
  2102. #else
  2103. {
  2104.   FRAME_PTR f;
  2105.   Lisp_Object lispy_dummy;
  2106.   enum scroll_bar_part party_dummy;
  2107.   Lisp_Object x, y;
  2108.   int col, row;
  2109.   unsigned long long_dummy;
  2110.  
  2111.   f = selected_frame;
  2112.   x = y = Qnil;
  2113.  
  2114.   /* It's okay for the hook to refrain from storing anything.  */
  2115.   if (mouse_position_hook)
  2116.     (*mouse_position_hook) (&f,
  2117.                 &lispy_dummy, &party_dummy,
  2118.                 &x, &y,
  2119.                 &long_dummy);
  2120.   if (! NILP (x))
  2121.     {
  2122.       col = XINT (x);
  2123.       row = XINT (y);
  2124.       pixel_to_glyph_coords (f, col, row, &col, &row, 0, 1);
  2125.       XSETINT (x, col);
  2126.       XSETINT (y, row);
  2127.     }
  2128.   lispy_dummy = Qnil;
  2129.   return Fcons (lispy_dummy, Fcons (x, y));
  2130. }
  2131.  
  2132. DEFUN ("mouse-pixel-position", Fmouse_pixel_position,
  2133.        Smouse_pixel_position, 0, 0, 0,
  2134.   "Return a list (FRAME X . Y) giving the current mouse frame and position.\n\
  2135. The position is given in pixel units, where (0, 0) is the\n\
  2136. upper-left corner.\n\
  2137. If Emacs is running on a mouseless terminal or hasn't been programmed\n\
  2138. to read the mouse position, it returns the selected frame for FRAME\n\
  2139. and nil for X and Y.")
  2140.   ()
  2141. {
  2142.   FRAME_PTR f;
  2143.   Lisp_Object lispy_dummy;
  2144.   enum scroll_bar_part party_dummy;
  2145.   Lisp_Object x, y;
  2146.   int col, row;
  2147.   unsigned long long_dummy;
  2148.  
  2149.   f = selected_frame;
  2150.   x = y = Qnil;
  2151.  
  2152.   /* It's okay for the hook to refrain from storing anything.  */
  2153.   if (mouse_position_hook)
  2154.     (*mouse_position_hook) (&f,
  2155.                 &lispy_dummy, &party_dummy,
  2156.                 &x, &y,
  2157.                 &long_dummy);
  2158.   lispy_dummy = Qnil;
  2159.   return Fcons (lispy_dummy, Fcons (x, y));
  2160. }
  2161. #endif /* HAVE_MOUSE */
  2162.  
  2163.  
  2164. #ifndef AMIGA
  2165. void
  2166. store_in_alist (alistptr, prop, val)
  2167.      Lisp_Object *alistptr, val;
  2168.      Lisp_Object prop;
  2169. {
  2170.   register Lisp_Object tem;
  2171.  
  2172.   tem = Fassq (prop, *alistptr);
  2173.   if (EQ (tem, Qnil))
  2174.     *alistptr = Fcons (Fcons (prop, val), *alistptr);
  2175.   else
  2176.     Fsetcdr (tem, val);
  2177. }
  2178. #endif
  2179.  
  2180. #ifndef AMIGA
  2181. DEFUN ("frame-parameters", Fframe_parameters, Sframe_parameters, 0, 1, 0,
  2182.   /* Don't confuse make-docfile by having two doc strings for this function.
  2183.      make-docfile does not pay attention to #if, for good reason!  */
  2184.   0)
  2185.   (frame)
  2186.      Lisp_Object frame;
  2187. {
  2188.   Lisp_Object alist;
  2189.   FRAME_PTR f;
  2190.  
  2191.   if (EQ (frame, Qnil))
  2192.     f = selected_frame;
  2193.   else
  2194.     {
  2195.       CHECK_FRAME (frame, 0);
  2196.       f = XFRAME (frame);
  2197.     }
  2198.  
  2199.   if (!FRAME_LIVE_P (f))
  2200.     return Qnil;
  2201.  
  2202.   alist = Qnil;
  2203.   store_in_alist (&alist, Qname, build_string ("emacs"));
  2204.   store_in_alist (&alist, Qheight, make_number (FRAME_HEIGHT (f)));
  2205.   store_in_alist (&alist, Qwidth, make_number (FRAME_WIDTH (f)));
  2206.   store_in_alist (&alist, Qmodeline, (FRAME_WANTS_MODELINE_P (f) ? Qt : Qnil));
  2207.   store_in_alist (&alist, Qminibuffer, FRAME_MINIBUF_WINDOW (f));
  2208.   store_in_alist (&alist, Qunsplittable, (FRAME_NO_SPLIT_P (f) ? Qt : Qnil));
  2209.   store_in_alist (&alist, Qmenu_bar_lines, (FRAME_MENU_BAR_LINES (f)));
  2210.  
  2211.   return alist;
  2212. }
  2213. #endif
  2214.  
  2215. #ifndef AMIGA
  2216. DEFUN ("modify-frame-parameters", Fmodify_frame_parameters, 
  2217.        Smodify_frame_parameters, 2, 2, 0,
  2218.   /* Don't confuse make-docfile by having two doc strings for this function.
  2219.      make-docfile does not pay attention to #if, for good reason!  */
  2220.   0)
  2221.   (frame, alist)
  2222.      Lisp_Object frame, alist;
  2223. {
  2224.   return Qnil;
  2225. }
  2226. #endif
  2227.  
  2228. DEFUN ("frame-live-p", Fframe_live_p, Sframe_live_p, 1, 1, 0,
  2229.   /* Don't confuse make-docfile by having two doc strings for this function.
  2230.      make-docfile does not pay attention to #if, for good reason!  */
  2231.   0)
  2232.   (frame)
  2233.      Lisp_Object frame;
  2234. {
  2235.   return Qt;
  2236. }
  2237.  
  2238. syms_of_frame ()
  2239. {
  2240.   Qheight = intern ("height");
  2241.   staticpro (&Qheight);
  2242.   Qminibuffer = intern ("minibuffer");
  2243.   staticpro (&Qminibuffer);
  2244.   Qmodeline = intern ("modeline");
  2245.   staticpro (&Qmodeline);
  2246.   Qname = intern ("name");
  2247.   staticpro (&Qname);
  2248.   Qunsplittable = intern ("unsplittable");
  2249.   staticpro (&Qunsplittable);
  2250.   Qmenu_bar_lines = intern ("menu-bar-lines");
  2251.   staticpro (&Qmenu_bar_lines);
  2252.   Qwidth = intern ("width");
  2253.   staticpro (&Qwidth);
  2254.  
  2255.   DEFVAR_LISP ("terminal-frame", &Vterminal_frame,
  2256.     "The initial frame-object, which represents Emacs's stdout.");
  2257.   XFASTINT (Vterminal_frame) = 0;
  2258.  
  2259. #ifdef AMIGA
  2260.   DEFVAR_LISP ("default-frame-alist", &Vdefault_frame_alist,
  2261.     "Alist of default values for frame creation.\n\
  2262. These may be set in your init file, like this:\n\
  2263.   (setq default-frame-alist '((width . 80) (height . 55)))\n\
  2264. These override values given in window system configuration data, like\n\
  2265. X Windows' defaults database.\n\
  2266. For values specific to the first Emacs frame, see `initial-frame-alist'.\n\
  2267. For values specific to the separate minibuffer frame, see\n\
  2268. `minibuffer-frame-alist'.");
  2269.   Vdefault_frame_alist = Qnil;
  2270. #endif /* AMIGA */
  2271.  
  2272. #ifdef USE_EXTERNAL_MENU_BAR
  2273.   the_only_param_alist = Qnil;
  2274.   staticpro(&the_only_param_alist);
  2275.   the_only_menu_bar_items = Qnil;
  2276.   staticpro(&the_only_menu_bar_items);
  2277.   the_only_menu_bar_vector = Qnil;
  2278.   staticpro(&the_only_menu_bar_vector);
  2279. #endif /* USE_EXTERNAL_MENU_BAR */
  2280. #ifdef USE_SCROLL_BARS
  2281.   the_only_scroll_bars = Qnil;
  2282.   staticpro(&the_only_scroll_bars);
  2283.   the_only_condemned_scroll_bars = Qnil;
  2284.   staticpro(&the_only_condemned_scroll_bars);
  2285. #endif /* USE_SCROLL_BARS */
  2286.  
  2287.   defsubr (&Sselected_frame);
  2288.   defsubr (&Sframe_first_window);
  2289.   defsubr (&Sframep);
  2290.   defsubr (&Sframe_char_height);
  2291.   defsubr (&Sframe_char_width);
  2292.   defsubr (&Sframe_pixel_height);
  2293.   defsubr (&Sframe_pixel_width);
  2294.   defsubr (&Sset_frame_height);
  2295.   defsubr (&Sset_frame_width);
  2296.   defsubr (&Sset_frame_size);
  2297.   defsubr (&Sset_screen_height);
  2298.   defsubr (&Sset_screen_width);
  2299.   defsubr (&Sframe_height);
  2300.   Ffset (intern ("screen-height"), intern ("frame-height"));
  2301.   defsubr (&Sframe_width);
  2302.   Ffset (intern ("screen-width"), intern ("frame-width"));
  2303.   defsubr (&Smouse_position);
  2304. #ifdef AMIGA
  2305.   defsubr (&Smouse_pixel_position);
  2306.   defsubr (&Smake_frame_visible);
  2307. #if 0
  2308.   defsubr (&Smake_frame_invisible);
  2309. #endif
  2310.   defsubr (&Sraise_frame);
  2311.   defsubr (&Slower_frame);
  2312. #endif
  2313.   defsubr (&Sframe_parameters);
  2314.   defsubr (&Smodify_frame_parameters);
  2315.   defsubr (&Sframe_live_p);
  2316. }
  2317.  
  2318. keys_of_frame ()
  2319. {
  2320. }
  2321.  
  2322. #endif /* not MULTI_FRAME */
  2323.