+#ifdef MULTI_KBOARD
+#define FRAME_KBOARD(f) ((f)->kboard)
+#else
+#define FRAME_KBOARD(f) (&the_only_kboard)
+#endif
+
+typedef struct frame *FRAME_PTR;
+
+#define XFRAME(p) (eassert (GC_FRAMEP(p)),(struct frame *) XPNTR (p))
+#define XSETFRAME(a, b) (XSETPSEUDOVECTOR (a, b, PVEC_FRAME))
+
+/* Given a window, return its frame as a Lisp_Object. */
+#define WINDOW_FRAME(w) (w)->frame
+
+/* Test a frame for particular kinds of display methods. */
+#define FRAME_TERMCAP_P(f) ((f)->output_method == output_termcap)
+#define FRAME_X_P(f) ((f)->output_method == output_x_window)
+#define FRAME_W32_P(f) ((f)->output_method == output_w32)
+#define FRAME_MSDOS_P(f) ((f)->output_method == output_msdos_raw)
+#define FRAME_MAC_P(f) ((f)->output_method == output_mac)
+
+/* FRAME_WINDOW_P tests whether the frame is a window, and is
+ defined to be the predicate for the window system being used. */
+
+#ifdef HAVE_X_WINDOWS
+#define FRAME_WINDOW_P(f) FRAME_X_P (f)
+#endif
+#ifdef HAVE_NTGUI
+#define FRAME_WINDOW_P(f) FRAME_W32_P (f)
+#endif
+#ifdef macintosh
+#define FRAME_WINDOW_P(f) FRAME_MAC_P (f)
+#endif
+#ifndef FRAME_WINDOW_P
+#define FRAME_WINDOW_P(f) (0)
+#endif
+
+/* Nonzero if frame F is still alive (not deleted). */
+#define FRAME_LIVE_P(f) ((f)->output_data.nothing != 0)
+
+/* Nonzero if frame F is a minibuffer-only frame. */
+#define FRAME_MINIBUF_ONLY_P(f) \
+ EQ (FRAME_ROOT_WINDOW (f), FRAME_MINIBUF_WINDOW (f))
+
+/* Nonzero if frame F contains a minibuffer window.
+ (If this is 0, F must use some other minibuffer window.) */
+#define FRAME_HAS_MINIBUF_P(f) ((f)->has_minibuffer)
+#define FRAME_HEIGHT(f) (f)->height
+
+/* Width of frame F, measured in character columns,
+ not including scroll bars if any. */
+#define FRAME_WIDTH(f) (f)->width
+
+/* Number of lines of frame F used for menu bar.
+ This is relevant on terminal frames and on
+ X Windows when not using the X toolkit.
+ These lines are counted in FRAME_HEIGHT. */
+#define FRAME_MENU_BAR_LINES(f) (f)->menu_bar_lines
+
+/* Number of lines of frame F used for the tool-bar. */
+
+#define FRAME_TOOL_BAR_LINES(f) (f)->tool_bar_lines
+
+/* Lines above the top-most window in frame F. */
+
+#define FRAME_TOP_MARGIN(F) \
+ (FRAME_MENU_BAR_LINES (F) + FRAME_TOOL_BAR_LINES (F))
+
+/* Nonzero if this frame should display a menu bar
+ in a way that does not use any text lines. */
+#if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (macintosh)
+#define FRAME_EXTERNAL_MENU_BAR(f) (f)->external_menu_bar
+#else
+#define FRAME_EXTERNAL_MENU_BAR(f) 0
+#endif
+#define FRAME_VISIBLE_P(f) ((f)->visible != 0)
+
+/* Nonzero if frame F is currently visible but hidden. */
+#define FRAME_OBSCURED_P(f) ((f)->visible > 1)
+
+/* Nonzero if frame F is currently iconified. */
+#define FRAME_ICONIFIED_P(f) (f)->iconified
+
+#define FRAME_SET_VISIBLE(f,p) \
+ ((f)->async_visible = (p), FRAME_SAMPLE_VISIBILITY (f))
+#define SET_FRAME_GARBAGED(f) (frame_garbaged = 1, f->garbaged = 1)
+#define FRAME_GARBAGED_P(f) (f)->garbaged
+
+/* Nonzero means do not allow splitting this frame's window. */
+#define FRAME_NO_SPLIT_P(f) (f)->no_split
+
+/* Not really implemented. */
+#define FRAME_WANTS_MODELINE_P(f) (f)->wants_modeline
+
+/* Nonzero if a size change has been requested for frame F
+ but not yet really put into effect. This can be true temporarily
+ when an X event comes in at a bad time. */
+#define FRAME_WINDOW_SIZES_CHANGED(f) (f)->window_sizes_changed
+/* When a size change is pending, these are the requested new sizes. */
+#define FRAME_NEW_HEIGHT(f) (f)->new_height
+#define FRAME_NEW_WIDTH(f) (f)->new_width
+
+/* The minibuffer window of frame F, if it has one; otherwise nil. */
+#define FRAME_MINIBUF_WINDOW(f) (f)->minibuffer_window
+
+/* The root window of the window tree of frame F. */
+#define FRAME_ROOT_WINDOW(f) (f)->root_window
+
+/* The currently selected window of the window tree of frame F. */
+#define FRAME_SELECTED_WINDOW(f) (f)->selected_window
+
+#define FRAME_INSERT_COST(f) (f)->insert_line_cost
+#define FRAME_DELETE_COST(f) (f)->delete_line_cost
+#define FRAME_INSERTN_COST(f) (f)->insert_n_lines_cost
+#define FRAME_DELETEN_COST(f) (f)->delete_n_lines_cost
+#define FRAME_MESSAGE_BUF(f) (f)->message_buf
+#define FRAME_SCROLL_BOTTOM_VPOS(f) (f)->scroll_bottom_vpos
+#define FRAME_FOCUS_FRAME(f) (f)->focus_frame
+
+/* Nonzero if frame F supports scroll bars.
+ If this is zero, then it is impossible to enable scroll bars
+ on frame F. */
+#define FRAME_CAN_HAVE_SCROLL_BARS(f) ((f)->can_have_scroll_bars)
+
+/* This frame slot says whether scroll bars are currently enabled for frame F,
+ and which side they are on. */
+#define FRAME_VERTICAL_SCROLL_BAR_TYPE(f) ((f)->vertical_scroll_bar_type)
+#define FRAME_HAS_VERTICAL_SCROLL_BARS(f) \
+ ((f)->vertical_scroll_bar_type != vertical_scroll_bar_none)
+#define FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT(f) \
+ ((f)->vertical_scroll_bar_type == vertical_scroll_bar_left)
+#define FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT(f) \
+ ((f)->vertical_scroll_bar_type == vertical_scroll_bar_right)
+
+/* Width that a scroll bar in frame F should have, if there is one.
+ Measured in pixels.
+ If scroll bars are turned off, this is still nonzero. */
+#define FRAME_SCROLL_BAR_PIXEL_WIDTH(f) ((f)->scroll_bar_pixel_width)
+
+/* Width that a scroll bar in frame F should have, if there is one.
+ Measured in columns (characters).
+ If scroll bars are turned off, this is still nonzero. */
+#define FRAME_SCROLL_BAR_COLS(f) ((f)->scroll_bar_cols)
+
+/* Width of a scroll bar in frame F, measured in columns (characters),
+ but only if scroll bars are on the left. If scroll bars are on
+ the right in this frame, or there are no scroll bars, value is 0. */
+
+#define FRAME_LEFT_SCROLL_BAR_WIDTH(f) \
+ (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (f) \
+ ? FRAME_SCROLL_BAR_COLS (f) \
+ : 0)
+
+/* Width of a scroll bar in frame F, measured in columns (characters),
+ but only if scroll bars are on the right. If scroll bars are on
+ the left in this frame, or there are no scroll bars, value is 0. */
+
+#define FRAME_RIGHT_SCROLL_BAR_WIDTH(f) \
+ (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f) \
+ ? FRAME_SCROLL_BAR_COLS (f) \
+ : 0)
+
+/* Width of a scroll bar in frame F, measured in columns (characters). */
+#define FRAME_SCROLL_BAR_WIDTH(f) \
+ (FRAME_HAS_VERTICAL_SCROLL_BARS (f) \
+ ? FRAME_SCROLL_BAR_COLS (f) \
+ : 0)
+
+/* Total width of frame F, in columns (characters),
+ including the width used by scroll bars if any. */
+#define FRAME_WINDOW_WIDTH(f) ((f)->window_width)
+
+/* Set the width of frame F to VAL.
+ VAL is the width of a full-frame window,
+ not including scroll bars. */
+#define SET_FRAME_WIDTH(f, val) \
+ ((f)->width = (val), \
+ (f)->window_width = FRAME_WINDOW_WIDTH_ARG (f, (f)->width))
+
+/* Given a value WIDTH for frame F's nominal width,
+ return the value that FRAME_WINDOW_WIDTH should have. */
+#define FRAME_WINDOW_WIDTH_ARG(f, width) \
+ ((width) \
+ + FRAME_SCROLL_BAR_WIDTH (f) \
+ + FRAME_FRINGE_COLS (f))
+
+/* Maximum + 1 legitimate value for FRAME_CURSOR_X. */
+#define FRAME_CURSOR_X_LIMIT(f) \
+ (FRAME_WIDTH (f) + FRAME_LEFT_SCROLL_BAR_WIDTH (f))
+
+/* Nonzero if frame F has scroll bars. */
+#define FRAME_SCROLL_BARS(f) ((f)->scroll_bars)
+
+#define FRAME_CONDEMNED_SCROLL_BARS(f) ((f)->condemned_scroll_bars)
+#define FRAME_MENU_BAR_ITEMS(f) ((f)->menu_bar_items)
+#define FRAME_COST_BAUD_RATE(f) ((f)->cost_calculation_baud_rate)
+
+/* Return a pointer to the face cache of frame F. */
+
+#define FRAME_FACE_CACHE(F) (F)->face_cache
+
+/* Return the size of message_buf of the frame F. We multiply the
+ width of the frame by 4 because multi-byte form may require at most
+ 4-byte for a character. */
+
+#define FRAME_MESSAGE_BUF_SIZE(f) (((int) (f)->width) * 4)
+
+/* Emacs's redisplay code could become confused if a frame's
+ visibility changes at arbitrary times. For example, if a frame is
+ visible while the desired glyphs are being built, but becomes
+ invisible before they are updated, then some rows of the
+ desired_glyphs will be left marked as enabled after redisplay is
+ complete, which should never happen. The next time the frame
+ becomes visible, redisplay will probably barf.
+
+ Currently, there are no similar situations involving iconified, but
+ the principle is the same.
+
+ So instead of having asynchronous input handlers directly set and
+ clear the frame's visibility and iconification flags, they just set
+ the async_visible and async_iconified flags; the redisplay code
+ calls the FRAME_SAMPLE_VISIBILITY macro before doing any redisplay,
+ which sets visible and iconified from their asynchronous
+ counterparts.
+
+ Synchronous code must use the FRAME_SET_VISIBLE macro.
+
+ Also, if a frame used to be invisible, but has just become visible,
+ it must be marked as garbaged, since redisplay hasn't been keeping
+ up its contents. */
+
+#define FRAME_SAMPLE_VISIBILITY(f) \
+ (((f)->async_visible && (f)->visible != (f)->async_visible) ? \
+ SET_FRAME_GARBAGED (f) : 0, \
+ (f)->visible = (f)->async_visible, \
+ (f)->iconified = (f)->async_iconified)
+
+#define CHECK_FRAME(x) \
+ do { \
+ if (! FRAMEP (x)) \
+ x = wrong_type_argument (Qframep, (x)); \
+ } while (0)
+
+#define CHECK_LIVE_FRAME(x) \
+ do { \
+ if (! FRAMEP (x) \
+ || ! FRAME_LIVE_P (XFRAME (x))) \
+ x = wrong_type_argument (Qframe_live_p, (x)); \
+ } while (0)
+
+/* FOR_EACH_FRAME (LIST_VAR, FRAME_VAR) followed by a statement is a
+ `for' loop which iterates over the elements of Vframe_list. The
+ loop will set FRAME_VAR, a Lisp_Object, to each frame in
+ Vframe_list in succession and execute the statement. LIST_VAR
+ should be a Lisp_Object too; it is used to iterate through the
+ Vframe_list.
+
+ This macro is a holdover from a time when multiple frames weren't always
+ supported. An alternate definition of the macro would expand to
+ something which executes the statement once. */
+
+#define FOR_EACH_FRAME(list_var, frame_var) \
+ for ((list_var) = Vframe_list; \
+ (CONSP (list_var) \
+ && (frame_var = XCAR (list_var), 1)); \
+ list_var = XCDR (list_var))
+
+
+extern Lisp_Object Qframep, Qframe_live_p, Qicon;
+extern Lisp_Object Qleft_fringe, Qright_fringe;
+
+extern struct frame *last_nonminibuf_frame;
+
+extern struct frame *make_terminal_frame P_ ((void));
+extern struct frame *make_frame P_ ((int));
+#ifdef HAVE_WINDOW_SYSTEM
+extern struct frame *make_minibuffer_frame P_ ((void));
+extern struct frame *make_frame_without_minibuffer P_ ((Lisp_Object,
+ struct kboard *,
+ Lisp_Object));
+#endif /* HAVE_WINDOW_SYSTEM */
+extern int other_visible_frames P_ ((struct frame *));
+
+extern Lisp_Object Vframe_list;
+extern Lisp_Object Vdefault_frame_alist;
+
+extern Lisp_Object Vterminal_frame;
+\f
+/* Device-independent scroll bar stuff. */
+
+/* Return the starting column (zero-based) of the vertical scroll bar
+ for window W. The column before this one is the last column we can
+ use for text. If the window touches the right edge of the frame,
+ we have extra space allocated for it. Otherwise, the scroll bar
+ takes over the window's rightmost columns. */
+
+#define WINDOW_VERTICAL_SCROLL_BAR_COLUMN(w) \
+ (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (XFRAME (WINDOW_FRAME (w))) ? \
+ (((XINT ((w)->left) + XINT ((w)->width)) \
+ < FRAME_WIDTH (XFRAME (WINDOW_FRAME (w)))) \
+ ? (XINT ((w)->left) + XINT ((w)->width) \
+ - FRAME_SCROLL_BAR_COLS (XFRAME (WINDOW_FRAME (w)))) \
+ : FRAME_WIDTH (XFRAME (WINDOW_FRAME (w)))) \
+ : XINT ((w)->left))
+
+/* Return the height in lines of the vertical scroll bar in w. If the
+ window has a mode line, don't make the scroll bar extend that far. */
+
+#define WINDOW_VERTICAL_SCROLL_BAR_HEIGHT(w) (window_internal_height (w))