diff options
Diffstat (limited to 'src/frame.c')
-rw-r--r-- | src/frame.c | 2550 |
1 files changed, 1529 insertions, 1021 deletions
diff --git a/src/frame.c b/src/frame.c index 1aff3a007ac..91b9bec82c3 100644 --- a/src/frame.c +++ b/src/frame.c @@ -1,6 +1,6 @@ /* Generic frame functions. -Copyright (C) 1993-1995, 1997, 1999-2017 Free Software Foundation, Inc. +Copyright (C) 1993-1995, 1997, 1999-2022 Free Software Foundation, Inc. This file is part of GNU Emacs. @@ -52,11 +52,14 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */ #ifdef USE_X_TOOLKIT #include "widget.h" #endif +#include "pdumper.h" /* The currently selected frame. */ - Lisp_Object selected_frame; +/* The selected frame the last time window change functions were run. */ +Lisp_Object old_selected_frame; + /* A frame which is not just a mini-buffer, or NULL if there are no such frames. This is usually the most recent such frame that was selected. */ @@ -65,15 +68,18 @@ static struct frame *last_nonminibuf_frame; /* False means there are no visible garbaged frames. */ bool frame_garbaged; +/* The default tab bar height for future frames. */ +int frame_default_tab_bar_height; + /* The default tool bar height for future frames. */ -#if defined USE_GTK || defined HAVE_NS +#ifdef HAVE_EXT_TOOL_BAR enum { frame_default_tool_bar_height = 0 }; #else int frame_default_tool_bar_height; #endif #ifdef HAVE_WINDOW_SYSTEM -static void x_report_frame_params (struct frame *, Lisp_Object *); +static void gui_report_frame_params (struct frame *, Lisp_Object *); #endif /* These setters are used only in this file, so they can be private. */ @@ -138,39 +144,9 @@ check_window_system (struct frame *f) /* Return the value of frame parameter PROP in frame FRAME. */ Lisp_Object -get_frame_param (register struct frame *frame, Lisp_Object prop) -{ - register Lisp_Object tem; - - tem = Fassq (prop, frame->param_alist); - if (EQ (tem, Qnil)) - return tem; - return Fcdr (tem); -} - - -void -frame_size_history_add (struct frame *f, Lisp_Object fun_symbol, - int width, int height, Lisp_Object rest) +get_frame_param (struct frame *frame, Lisp_Object prop) { - Lisp_Object frame; - - XSETFRAME (frame, f); - if (CONSP (frame_size_history) - && INTEGERP (XCAR (frame_size_history)) - && 0 < XINT (XCAR (frame_size_history))) - frame_size_history = - Fcons (make_number (XINT (XCAR (frame_size_history)) - 1), - Fcons (list4 - (frame, fun_symbol, - ((width > 0) - ? list4 (make_number (FRAME_TEXT_WIDTH (f)), - make_number (FRAME_TEXT_HEIGHT (f)), - make_number (width), - make_number (height)) - : Qnil), - rest), - XCDR (frame_size_history))); + return Fcdr (Fassq (prop, frame->param_alist)); } @@ -188,55 +164,60 @@ frame_inhibit_resize (struct frame *f, bool horizontal, Lisp_Object parameter) || (CONSP (frame_inhibit_implied_resize) && !NILP (Fmemq (parameter, frame_inhibit_implied_resize))) || (horizontal - && !EQ (fullscreen, Qnil) && !EQ (fullscreen, Qfullheight)) + && !NILP (fullscreen) && !EQ (fullscreen, Qfullheight)) || (!horizontal - && !EQ (fullscreen, Qnil) && !EQ (fullscreen, Qfullwidth)) + && !NILP (fullscreen) && !EQ (fullscreen, Qfullwidth)) || FRAME_TERMCAP_P (f) || FRAME_MSDOS_P (f)) : ((horizontal && f->inhibit_horizontal_resize) || (!horizontal && f->inhibit_vertical_resize))); - if (inhibit && !FRAME_TERMCAP_P (f) && !FRAME_MSDOS_P (f)) - frame_size_history_add - (f, Qframe_inhibit_resize, 0, 0, - list5 (horizontal ? Qt : Qnil, parameter, - f->after_make_frame ? Qt : Qnil, - frame_inhibit_implied_resize, - fullscreen)); return inhibit; } + +/** Set menu bar lines for a TTY frame. */ static void set_menu_bar_lines (struct frame *f, Lisp_Object value, Lisp_Object oldval) { - int nlines; int olines = FRAME_MENU_BAR_LINES (f); + int nlines = TYPE_RANGED_FIXNUMP (int, value) ? XFIXNUM (value) : 0; /* Right now, menu bars don't work properly in minibuf-only frames; most of the commands try to apply themselves to the minibuffer frame itself, and get an error because you can't switch buffers in or split the minibuffer window. */ - if (FRAME_MINIBUF_ONLY_P (f)) - return; + if (!FRAME_MINIBUF_ONLY_P (f) && nlines != olines) + { + windows_or_buffers_changed = 14; + FRAME_MENU_BAR_LINES (f) = FRAME_MENU_BAR_HEIGHT (f) = nlines; + change_frame_size (f, FRAME_PIXEL_WIDTH (f), FRAME_PIXEL_HEIGHT (f), + false, true, false); + } +} - if (TYPE_RANGED_INTEGERP (int, value)) - nlines = XINT (value); - else - nlines = 0; - if (nlines != olines) +/** Set tab bar lines for a TTY frame. */ +static void +set_tab_bar_lines (struct frame *f, Lisp_Object value, Lisp_Object oldval) +{ + int olines = FRAME_TAB_BAR_LINES (f); + int nlines = TYPE_RANGED_FIXNUMP (int, value) ? XFIXNUM (value) : 0; + + /* Right now, tab bars don't work properly in minibuf-only frames; + most of the commands try to apply themselves to the minibuffer + frame itself, and get an error because you can't switch buffers + in or split the minibuffer window. */ + if (!FRAME_MINIBUF_ONLY_P (f) && nlines != olines) { windows_or_buffers_changed = 14; - FRAME_MENU_BAR_LINES (f) = nlines; - FRAME_MENU_BAR_HEIGHT (f) = nlines * FRAME_LINE_HEIGHT (f); - change_frame_size (f, FRAME_COLS (f), - FRAME_LINES (f) + olines - nlines, - 0, 1, 0, 0); + FRAME_TAB_BAR_LINES (f) = FRAME_TAB_BAR_HEIGHT (f) = nlines; + change_frame_size (f, FRAME_PIXEL_WIDTH (f), FRAME_PIXEL_HEIGHT (f), + false, true, false); } } Lisp_Object Vframe_list; - DEFUN ("framep", Fframep, Sframep, 1, 1, 0, doc: /* Return non-nil if OBJECT is a frame. Value is: @@ -244,7 +225,9 @@ Value is: `x' for an Emacs frame that is really an X window, `w32' for an Emacs frame that is a window on MS-Windows display, `ns' for an Emacs frame on a GNUstep or Macintosh Cocoa display, - `pc' for a direct-write MS-DOS frame. + `pc' for a direct-write MS-DOS frame, + `pgtk' for an Emacs frame running on pure GTK. + `haiku' for an Emacs frame running in Haiku. See also `frame-live-p'. */) (Lisp_Object object) { @@ -263,6 +246,10 @@ See also `frame-live-p'. */) return Qpc; case output_ns: return Qns; + case output_pgtk: + return Qpgtk; + case output_haiku: + return Qhaiku; default: emacs_abort (); } @@ -290,6 +277,8 @@ The value is a symbol: `w32' for an Emacs frame that is a window on MS-Windows display, `ns' for an Emacs frame on a GNUstep or Macintosh Cocoa display, `pc' for a direct-write MS-DOS frame. + `pgtk' for an Emacs frame using pure GTK facilities. + `haiku' for an Emacs frame running in Haiku. FRAME defaults to the currently selected frame. @@ -316,12 +305,12 @@ predicates which report frame's specific UI-related capabilities. */) /* Placeholder used by temacs -nw before window.el is loaded. */ DEFUN ("frame-windows-min-size", Fframe_windows_min_size, Sframe_windows_min_size, 4, 4, 0, - doc: /* */ + doc: /* SKIP: real doc in window.el. */ attributes: const) (Lisp_Object frame, Lisp_Object horizontal, Lisp_Object ignore, Lisp_Object pixelwise) { - return make_number (0); + return make_fixnum (0); } /** @@ -338,10 +327,13 @@ DEFUN ("frame-windows-min-size", Fframe_windows_min_size, * * If `frame-windows-min-size' is called, it will make sure that the * return value accommodates all windows of FRAME respecting the values - * of `window-min-height' (`window-min-width' if HORIZONTAL is non-nil). - * With IGNORE non-nil the values of these variables are ignored. + * of `window-min-height' (`window-min-width' if HORIZONTAL is + * non-nil) and `window-safe-min-height' (`window-safe-min-width') + * according to IGNORE (see `window-min-size'). * - * In either case, never return a value less than 1. + * In either case, never return a value less than 1. For TTY frames, + * additionally limit the minimum frame height to a value large enough + * to support menu bar, tab bar, mode line and echo area. */ static int frame_windows_min_size (Lisp_Object frame, Lisp_Object horizontal, @@ -349,27 +341,47 @@ frame_windows_min_size (Lisp_Object frame, Lisp_Object horizontal, { struct frame *f = XFRAME (frame); Lisp_Object par_size; + int retval; if ((!NILP (horizontal) - && NUMBERP (par_size = get_frame_param (f, Qmin_width))) + && RANGED_FIXNUMP (INT_MIN, + par_size = get_frame_param (f, Qmin_width), + INT_MAX)) || (NILP (horizontal) - && NUMBERP (par_size = get_frame_param (f, Qmin_height)))) + && RANGED_FIXNUMP (INT_MIN, + par_size = get_frame_param (f, Qmin_height), + INT_MAX))) { - int min_size = XINT (par_size); + int min_size = XFIXNUM (par_size); /* Don't allow phantom frames. */ if (min_size < 1) min_size = 1; - return (NILP (pixelwise) - ? min_size - : min_size * (NILP (horizontal) - ? FRAME_LINE_HEIGHT (f) - : FRAME_COLUMN_WIDTH (f))); + retval = (NILP (pixelwise) + ? min_size + : min_size * (NILP (horizontal) + ? FRAME_LINE_HEIGHT (f) + : FRAME_COLUMN_WIDTH (f))); } else - return XINT (call4 (Qframe_windows_min_size, frame, horizontal, - ignore, pixelwise)); + retval = XFIXNUM (call4 (Qframe_windows_min_size, frame, horizontal, + ignore, pixelwise)); + + /* Don't allow too small height of text-mode frames, or else cm.c + might abort in cmcheckmagic. */ + if ((FRAME_TERMCAP_P (f) || FRAME_MSDOS_P (f)) && NILP (horizontal)) + { + int min_height = (FRAME_MENU_BAR_LINES (f) + + FRAME_TAB_BAR_LINES (f) + + FRAME_WANTS_MODELINE_P (f) + + 2); /* one text line and one echo-area line */ + + if (retval < min_height) + retval = min_height; + } + + return retval; } @@ -426,9 +438,10 @@ keep_ratio (struct frame *f, struct frame *p, int old_width, int old_height, if (CONSP (keep_ratio) && (NILP (Fcar (keep_ratio)) || EQ (Fcar (keep_ratio), Qheight_only)) - && p->pixel_width - f->pixel_width < pos_x) + && FRAME_PIXEL_WIDTH (p) - FRAME_PIXEL_WIDTH (f) < pos_x) { - int p_f_width = p->pixel_width - f->pixel_width; + int p_f_width + = FRAME_PIXEL_WIDTH (p) - FRAME_PIXEL_WIDTH (f); if (p_f_width <= 0) pos_x = 0; @@ -448,14 +461,15 @@ keep_ratio (struct frame *f, struct frame *p, int old_width, int old_height, if (CONSP (keep_ratio) && (NILP (Fcar (keep_ratio)) || EQ (Fcar (keep_ratio), Qwidth_only)) - && p->pixel_height - f->pixel_height < pos_y) + && FRAME_PIXEL_HEIGHT (p) - FRAME_PIXEL_HEIGHT (f) < pos_y) /* When positional adjustment was requested and the width of F should remain unaltered, try to constrain F to its parent. This means that when the parent frame is enlarged later the child's original position won't get restored. */ { - int p_f_height = p->pixel_height - f->pixel_height; + int p_f_height + = FRAME_PIXEL_HEIGHT (p) - FRAME_PIXEL_HEIGHT (f); if (p_f_height <= 0) pos_y = 0; @@ -466,7 +480,8 @@ keep_ratio (struct frame *f, struct frame *p, int old_width, int old_height, f->top_pos = pos_y; } - x_set_offset (f, pos_x, pos_y, -1); + if (FRAME_TERMINAL (f)->set_frame_offset_hook) + FRAME_TERMINAL (f)->set_frame_offset_hook (f, pos_x, pos_y, -1); } if (!CONSP (keep_ratio) || !NILP (Fcar (keep_ratio))) @@ -474,206 +489,326 @@ keep_ratio (struct frame *f, struct frame *p, int old_width, int old_height, if (CONSP (keep_ratio) && EQ (Fcar (keep_ratio), Qheight_only)) pixel_width = -1; else - { - pixel_width = (int)(f->pixel_width * width_factor + 0.5); - pixel_width = FRAME_PIXEL_TO_TEXT_WIDTH (f, pixel_width); - } + pixel_width + = (int)(FRAME_PIXEL_WIDTH (f) * width_factor + 0.5); if (CONSP (keep_ratio) && EQ (Fcar (keep_ratio), Qwidth_only)) pixel_height = -1; else - { - pixel_height = (int)(f->pixel_height * height_factor + 0.5); - pixel_height = FRAME_PIXEL_TO_TEXT_HEIGHT (f, pixel_height); - } + pixel_height + = (int)(FRAME_PIXEL_HEIGHT (f) * height_factor + 0.5); - adjust_frame_size (f, pixel_width, pixel_height, 1, 0, - Qkeep_ratio); + adjust_frame_size (f, FRAME_PIXEL_TO_TEXT_WIDTH (f, pixel_width), + FRAME_PIXEL_TO_TEXT_HEIGHT (f, pixel_height), 1, + false, Qkeep_ratio); } } } #endif +static void +frame_size_history_adjust (struct frame *f, int inhibit, Lisp_Object parameter, + int old_text_width, int old_text_height, + int new_text_width, int new_text_height, + int old_text_cols, int old_text_lines, + int new_text_cols, int new_text_lines, + int old_native_width, int old_native_height, + int new_native_width, int new_native_height, + int old_inner_width, int old_inner_height, + int new_inner_width, int new_inner_height, + int min_inner_width, int min_inner_height, + bool inhibit_horizontal, bool inhibit_vertical) +{ + Lisp_Object frame; + + XSETFRAME (frame, f); + if (CONSP (frame_size_history) + && FIXNUMP (XCAR (frame_size_history)) + && 0 < XFIXNUM (XCAR (frame_size_history))) + frame_size_history = + Fcons (make_fixnum (XFIXNUM (XCAR (frame_size_history)) - 1), + Fcons (Fcons (list4 (frame, make_fixnum (5), + make_fixnum (inhibit), parameter), + list5 (list4i (old_text_width, old_text_height, + new_text_width, new_text_height), + list4i (old_text_cols, old_text_lines, + new_text_cols, new_text_lines), + list4i (old_native_width, old_native_height, + new_native_width, new_native_height), + list4i (old_inner_width, old_inner_height, + new_inner_width, new_inner_height), + list4 (make_fixnum (min_inner_width), + make_fixnum (min_inner_height), + inhibit_horizontal ? Qt : Qnil, + inhibit_vertical ? Qt : Qnil))), + XCDR (frame_size_history))); +} + + +void +frame_size_history_plain (struct frame *f, Lisp_Object parameter) +{ + Lisp_Object frame; + + XSETFRAME (frame, f); + if (CONSP (frame_size_history) + && FIXNUMP (XCAR (frame_size_history)) + && 0 < XFIXNUM (XCAR (frame_size_history))) + frame_size_history = + Fcons (make_fixnum (XFIXNUM (XCAR (frame_size_history)) - 1), + Fcons (Fcons (list3 (frame, make_fixnum (1), parameter), Qt), + XCDR (frame_size_history))); +} + + +void +frame_size_history_extra (struct frame *f, Lisp_Object parameter, + int pixel_width, int pixel_height, + int extra_width, int extra_height, + int delayed_width, int delayed_height) +{ + Lisp_Object frame; + + XSETFRAME (frame, f); + if (CONSP (frame_size_history) + && FIXNUMP (XCAR (frame_size_history)) + && 0 < XFIXNUM (XCAR (frame_size_history))) + frame_size_history = + Fcons (make_fixnum (XFIXNUM (XCAR (frame_size_history)) - 1), + Fcons (Fcons (list3 (frame, make_fixnum (2), parameter), + list2 (list4i (pixel_width, pixel_height, + extra_width, extra_height), + list2i (delayed_width, delayed_height))), + XCDR (frame_size_history))); +} + + /** * adjust_frame_size: * - * Adjust size of frame F. NEW_WIDTH and NEW_HEIGHT specify the new - * text size of F in pixels. A value of -1 means no change is requested - * for that direction (but the frame may still have to be resized to - * accommodate windows with their minimum sizes). This can either issue - * a request to resize the frame externally (via x_set_window_size), to - * resize the frame internally (via resize_frame_windows) or do nothing - * at all. + * Adjust size of frame F. NEW_TEXT_WIDTH and NEW_TEXT_HEIGHT specify + * the new text size of F in pixels. When INHIBIT equals 2, 3 or 4, a + * value of -1 means to leave the text size of F unchanged and adjust, + * if necessary and possible, F's native size accordingly. When INHIBIT + * equals 0, 1 or 5, a negative value means that the frame has been (or + * should be) made pathologically small which usually means that parts + * of the frame's windows may not be entirely visible. + * + * The effect of calling this function can be to either issue a request + * to resize the frame externally (via set_window_size_hook), to resize + * the frame internally (via resize_frame_windows) or to do nothing. * - * The argument INHIBIT can assume the following values: + * The argument INHIBIT controls whether set_window_size_hook may be + * called and can assume the following values: * - * 0 means to unconditionally call x_set_window_size even if sizes + * 0 means to unconditionally call set_window_size_hook even if sizes * apparently do not change. Fx_create_frame uses this to pass the * initial size to the window manager. * - * 1 means to call x_set_window_size if the native frame size really - * changes. Fset_frame_size, Fset_frame_height, ... use this. + * 1 means to call set_window_size_hook if the native frame size should + * change. Fset_frame_size and friends and width and height parameter + * changes use this. * - * 2 means to call x_set_window_size provided frame_inhibit_resize - * allows it. The menu and tool bar code use this ("3" won't work - * here in general because menu and tool bar are often not counted in - * the frame's text height). + * 2 means to call set_window_size_hook provided frame_inhibit_resize + * allows it. The code updating external menu and tool bars uses this + * to keep the height of the native frame unaltered when one of these + * bars is added or removed. This means that Emacs has to work + * against the window manager which usually tries to keep the combined + * height (native frame plus bar) unaltered. * - * 3 means call x_set_window_size if window minimum sizes must be - * preserved or frame_inhibit_resize allows it. x_set_left_fringe, - * x_set_scroll_bar_width, x_new_font ... use (or should use) this. + * 3 means to call set_window_size_hook if window minimum sizes must be + * preserved or frame_inhibit_resize allows it. This is the default + * for parameters accounted for in a frame's text size like fringes, + * scroll bars, internal border, tab bar, internal tool and menu bars. + * It's also used when the frame's default font changes. * - * 4 means call x_set_window_size only if window minimum sizes must be - * preserved. x_set_right_divider_width, x_set_border_width and the - * code responsible for wrapping the tool bar use this. + * 4 means to call set_window_size_hook only if window minimum sizes + * must be preserved. The code for setting up window dividers and + * that responsible for wrapping the (internal) tool bar use this. * - * 5 means to never call x_set_window_size. change_frame_size uses - * this. - * - * Note that even when x_set_window_size is not called, individual - * windows may have to be resized (via `window--sanitize-window-sizes') - * in order to support minimum size constraints. + * 5 means to never call set_window_size_hook. Usually this means to + * call resize_frame_windows. change_frame_size uses this. * * PRETEND is as for change_frame_size. PARAMETER, if non-nil, is the * symbol of the parameter changed (like `menu-bar-lines', `font', ...). * This is passed on to frame_inhibit_resize to let the latter decide on - * a case-by-case basis whether the frame may be resized externally. + * a case-by-case basis whether set_window_size_hook should be called. */ void -adjust_frame_size (struct frame *f, int new_width, int new_height, int inhibit, - bool pretend, Lisp_Object parameter) +adjust_frame_size (struct frame *f, int new_text_width, int new_text_height, + int inhibit, bool pretend, Lisp_Object parameter) { int unit_width = FRAME_COLUMN_WIDTH (f); int unit_height = FRAME_LINE_HEIGHT (f); - int old_pixel_width = FRAME_PIXEL_WIDTH (f); - int old_pixel_height = FRAME_PIXEL_HEIGHT (f); - int old_cols = FRAME_COLS (f); - int old_lines = FRAME_LINES (f); - int new_pixel_width, new_pixel_height; - /* The following two values are calculated from the old frame pixel - sizes and any "new" settings for tool bar, menu bar and internal - borders. We do it this way to detect whether we have to call - x_set_window_size as consequence of the new settings. */ - int windows_width = FRAME_WINDOWS_WIDTH (f); - int windows_height = FRAME_WINDOWS_HEIGHT (f); - int min_windows_width, min_windows_height; - /* These are a bit tedious, maybe we should use a macro. */ + int old_native_width = FRAME_PIXEL_WIDTH (f); + int old_native_height = FRAME_PIXEL_HEIGHT (f); + int new_native_width, new_native_height; + /* The desired minimum inner width and height of the frame calculated + via 'frame-windows-min-size'. */ + int min_inner_width, min_inner_height; + /* Get the "old" inner width, height and position of F via its root + window and the minibuffer window. We cannot use FRAME_INNER_WIDTH + and FRAME_INNER_HEIGHT here since the internal border and the top + margin may have been already set to new values. */ struct window *r = XWINDOW (FRAME_ROOT_WINDOW (f)); - int old_windows_width = WINDOW_PIXEL_WIDTH (r); - int old_windows_height + int old_inner_width = WINDOW_PIXEL_WIDTH (r); + int old_inner_height = (WINDOW_PIXEL_HEIGHT (r) + ((FRAME_HAS_MINIBUF_P (f) && !FRAME_MINIBUF_ONLY_P (f)) ? WINDOW_PIXEL_HEIGHT (XWINDOW (FRAME_MINIBUF_WINDOW (f))) : 0)); - int new_windows_width, new_windows_height; + int new_inner_width, new_inner_height; + int old_text_cols = FRAME_COLS (f); + int old_text_lines = FRAME_LINES (f); + int new_text_cols, new_text_lines; int old_text_width = FRAME_TEXT_WIDTH (f); int old_text_height = FRAME_TEXT_HEIGHT (f); - /* If a size is < 0 use the old value. */ - int new_text_width = (new_width >= 0) ? new_width : old_text_width; - int new_text_height = (new_height >= 0) ? new_height : old_text_height; - int new_cols, new_lines; bool inhibit_horizontal, inhibit_vertical; Lisp_Object frame; XSETFRAME (frame, f); - frame_size_history_add - (f, Qadjust_frame_size_1, new_text_width, new_text_height, - list2 (parameter, make_number (inhibit))); - - /* The following two values are calculated from the old window body - sizes and any "new" settings for scroll bars, dividers, fringes and - margins (though the latter should have been processed already). */ - min_windows_width - = frame_windows_min_size (frame, Qt, (inhibit == 5) ? Qt : Qnil, Qt); - min_windows_height - = frame_windows_min_size (frame, Qnil, (inhibit == 5) ? Qt : Qnil, Qt); + min_inner_width + = frame_windows_min_size (frame, Qt, (inhibit == 5) ? Qsafe : Qnil, Qt); + min_inner_height + = frame_windows_min_size (frame, Qnil, (inhibit == 5) ? Qsafe : Qnil, Qt); if (inhibit >= 2 && inhibit <= 4) /* When INHIBIT is in [2..4] inhibit if the "old" window sizes stay within the limits and either resizing is inhibited or INHIBIT equals 4. */ { - inhibit_horizontal = (windows_width >= min_windows_width + if (new_text_width == -1) + new_text_width = FRAME_TEXT_WIDTH (f); + if (new_text_height == -1) + new_text_height = FRAME_TEXT_HEIGHT (f); + + inhibit_horizontal = (FRAME_INNER_WIDTH (f) >= min_inner_width && (inhibit == 4 || frame_inhibit_resize (f, true, parameter))); - inhibit_vertical = (windows_height >= min_windows_height + inhibit_vertical = (FRAME_INNER_HEIGHT (f) >= min_inner_height && (inhibit == 4 || frame_inhibit_resize (f, false, parameter))); } else - /* Otherwise inhibit if INHIBIT equals 5. */ + /* Otherwise inhibit if INHIBIT equals 5. If we wanted to overrule + the WM do that here (could lead to some sort of eternal fight + with the WM). */ inhibit_horizontal = inhibit_vertical = inhibit == 5; - new_pixel_width = ((inhibit_horizontal && (inhibit < 5)) - ? old_pixel_width - : max (FRAME_TEXT_TO_PIXEL_WIDTH (f, new_text_width), - min_windows_width - + 2 * FRAME_INTERNAL_BORDER_WIDTH (f))); - new_windows_width = new_pixel_width - 2 * FRAME_INTERNAL_BORDER_WIDTH (f); - new_text_width = FRAME_PIXEL_TO_TEXT_WIDTH (f, new_pixel_width); - new_cols = new_text_width / unit_width; - - new_pixel_height = ((inhibit_vertical && (inhibit < 5)) - ? old_pixel_height - : max (FRAME_TEXT_TO_PIXEL_HEIGHT (f, new_text_height), - min_windows_height - + FRAME_TOP_MARGIN_HEIGHT (f) + new_native_width = ((inhibit_horizontal && inhibit < 5) + ? old_native_width + : max (FRAME_TEXT_TO_PIXEL_WIDTH (f, new_text_width), + min_inner_width + 2 * FRAME_INTERNAL_BORDER_WIDTH (f))); - new_windows_height = (new_pixel_height - - FRAME_TOP_MARGIN_HEIGHT (f) - - 2 * FRAME_INTERNAL_BORDER_WIDTH (f)); - new_text_height = FRAME_PIXEL_TO_TEXT_HEIGHT (f, new_pixel_height); - new_lines = new_text_height / unit_height; + new_inner_width = new_native_width - 2 * FRAME_INTERNAL_BORDER_WIDTH (f); + new_text_width = FRAME_PIXEL_TO_TEXT_WIDTH (f, new_native_width); + new_text_cols = new_text_width / unit_width; + + new_native_height = ((inhibit_vertical && inhibit < 5) + ? old_native_height + : max (FRAME_TEXT_TO_PIXEL_HEIGHT (f, new_text_height), + min_inner_height + + FRAME_TOP_MARGIN_HEIGHT (f) + + 2 * FRAME_INTERNAL_BORDER_WIDTH (f))); + new_inner_height = (new_native_height + - FRAME_TOP_MARGIN_HEIGHT (f) + - 2 * FRAME_INTERNAL_BORDER_WIDTH (f)); + new_text_height = FRAME_PIXEL_TO_TEXT_HEIGHT (f, new_native_height); + new_text_lines = new_text_height / unit_height; -#ifdef HAVE_WINDOW_SYSTEM if (FRAME_WINDOW_P (f) - && f->can_x_set_window_size + && f->can_set_window_size + /* For inhibit == 1 call the window_size_hook only if a native + size changes. For inhibit == 0 or inhibit == 2 always call + it. */ && ((!inhibit_horizontal - && (new_pixel_width != old_pixel_width + && (new_native_width != old_native_width || inhibit == 0 || inhibit == 2)) || (!inhibit_vertical - && (new_pixel_height != old_pixel_height + && (new_native_height != old_native_height || inhibit == 0 || inhibit == 2)))) - /* We are either allowed to change the frame size or the minimum - sizes request such a change. Do not care for fixing minimum - sizes here, we do that eventually when we're called from - change_frame_size. */ { - /* Make sure we respect fullheight and fullwidth. */ - if (inhibit_horizontal) - new_text_width = old_text_width; - else if (inhibit_vertical) - new_text_height = old_text_height; - - frame_size_history_add - (f, Qadjust_frame_size_2, new_text_width, new_text_height, - list2 (inhibit_horizontal ? Qt : Qnil, - inhibit_vertical ? Qt : Qnil)); - - x_set_window_size (f, 0, new_text_width, new_text_height, 1); + if (inhibit == 2 +#ifdef USE_MOTIF + && !EQ (parameter, Qmenu_bar_lines) +#endif + && (f->new_width >= 0 || f->new_height >= 0)) + /* For implied resizes with inhibit 2 (external menu and tool + bar) pick up any new sizes the display engine has not + processed yet. Otherwise, we would request the old sizes + which will make this request appear as a request to set new + sizes and have the WM react accordingly which is not TRT. + + We don't that for the external menu bar on Motif. + Otherwise, switching off the menu bar will shrink the frame + and switching it on will not enlarge it. */ + { + if (f->new_width >= 0) + new_native_width = f->new_width; + if (f->new_height >= 0) + new_native_height = f->new_height; + } + + if (CONSP (frame_size_history)) + frame_size_history_adjust (f, inhibit, parameter, + old_text_width, old_text_height, + new_text_width, new_text_height, + old_text_cols, old_text_lines, + new_text_cols, new_text_lines, + old_native_width, old_native_height, + new_native_width, new_native_height, + old_inner_width, old_inner_height, + new_inner_width, new_inner_height, + min_inner_width, min_inner_height, + inhibit_horizontal, inhibit_vertical); + + if (inhibit == 0 || inhibit == 1) + { + f->new_width = new_native_width; + f->new_height = new_native_height; + /* Resetting f->new_size_p is controversial: It might cause + do_pending_window_change drop a previous request and we are + in troubles when the window manager does not honor the + request we issue here. */ + f->new_size_p = false; + } + + if (FRAME_TERMINAL (f)->set_window_size_hook) + FRAME_TERMINAL (f)->set_window_size_hook + (f, 0, new_native_width, new_native_height); f->resized_p = true; return; } -#endif - if (new_text_width == old_text_width + if (CONSP (frame_size_history)) + frame_size_history_adjust (f, inhibit, parameter, + old_text_width, old_text_height, + new_text_width, new_text_height, + old_text_cols, old_text_lines, + new_text_cols, new_text_lines, + old_native_width, old_native_height, + new_native_width, new_native_height, + old_inner_width, old_inner_height, + new_inner_width, new_inner_height, + min_inner_width, min_inner_height, + inhibit_horizontal, inhibit_vertical); + + if ((XWINDOW (FRAME_ROOT_WINDOW (f))->pixel_top + == FRAME_TOP_MARGIN_HEIGHT (f)) + && new_text_width == old_text_width && new_text_height == old_text_height - && new_windows_width == old_windows_width - && new_windows_height == old_windows_height - && new_pixel_width == old_pixel_width - && new_pixel_height == old_pixel_height - && new_cols == old_cols - && new_lines == old_lines) - /* No change. Sanitize window sizes and return. */ - { - sanitize_window_sizes (Qt); - sanitize_window_sizes (Qnil); - - return; - } + && new_inner_width == old_inner_width + && new_inner_height == old_inner_height + /* We might be able to drop these but some doubts remain. */ + && new_native_width == old_native_width + && new_native_height == old_native_height + && new_text_cols == old_text_cols + && new_text_lines == old_text_lines) + /* No change. */ + return; block_input (); @@ -682,60 +817,67 @@ adjust_frame_size (struct frame *f, int new_width, int new_height, int inhibit, our video hardware. Try to find the smallest size greater or equal to the requested dimensions, while accounting for the fact that the menu-bar lines are not counted in the frame height. */ - int dos_new_lines = new_lines + FRAME_TOP_MARGIN (f); - dos_set_window_size (&dos_new_lines, &new_cols); - new_lines = dos_new_lines - FRAME_TOP_MARGIN (f); + int dos_new_text_lines = new_text_lines + FRAME_TOP_MARGIN (f); + + dos_set_window_size (&dos_new_text_lines, &new_text_cols); + new_text_lines = dos_new_text_lines - FRAME_TOP_MARGIN (f); #endif - if (new_windows_width != old_windows_width) + if (new_inner_width != old_inner_width) { - resize_frame_windows (f, new_windows_width, 1, 1); + resize_frame_windows (f, new_inner_width, true); /* MSDOS frames cannot PRETEND, as they change frame size by manipulating video hardware. */ if ((FRAME_TERMCAP_P (f) && !pretend) || FRAME_MSDOS_P (f)) - FrameCols (FRAME_TTY (f)) = new_cols; + FrameCols (FRAME_TTY (f)) = new_text_cols; -#if defined (HAVE_WINDOW_SYSTEM) && ! defined (USE_GTK) && ! defined (HAVE_NS) +#if defined (HAVE_WINDOW_SYSTEM) + if (WINDOWP (f->tab_bar_window)) + { + XWINDOW (f->tab_bar_window)->pixel_width = new_inner_width; + XWINDOW (f->tab_bar_window)->total_cols + = new_inner_width / unit_width; + } +#endif + +#if defined (HAVE_WINDOW_SYSTEM) && ! defined (HAVE_EXT_TOOL_BAR) if (WINDOWP (f->tool_bar_window)) { - XWINDOW (f->tool_bar_window)->pixel_width = new_windows_width; + XWINDOW (f->tool_bar_window)->pixel_width = new_inner_width; XWINDOW (f->tool_bar_window)->total_cols - = new_windows_width / unit_width; + = new_inner_width / unit_width; } #endif } - else if (new_cols != old_cols) + else if (new_text_cols != old_text_cols) call2 (Qwindow__pixel_to_total, frame, Qt); - if (new_windows_height != old_windows_height + if (new_inner_height != old_inner_height /* When the top margin has changed we have to recalculate the top edges of all windows. No such calculation is necessary for the left edges. */ || WINDOW_TOP_PIXEL_EDGE (r) != FRAME_TOP_MARGIN_HEIGHT (f)) { - resize_frame_windows (f, new_windows_height, 0, 1); + resize_frame_windows (f, new_inner_height, false); /* MSDOS frames cannot PRETEND, as they change frame size by manipulating video hardware. */ if ((FRAME_TERMCAP_P (f) && !pretend) || FRAME_MSDOS_P (f)) - FrameRows (FRAME_TTY (f)) = new_lines + FRAME_TOP_MARGIN (f); + FrameRows (FRAME_TTY (f)) = new_text_lines + FRAME_TOP_MARGIN (f); } - else if (new_lines != old_lines) + else if (new_text_lines != old_text_lines) call2 (Qwindow__pixel_to_total, frame, Qnil); - frame_size_history_add - (f, Qadjust_frame_size_3, new_text_width, new_text_height, - list4 (make_number (old_pixel_width), make_number (old_pixel_height), - make_number (new_pixel_width), make_number (new_pixel_height))); - /* Assign new sizes. */ + FRAME_COLS (f) = new_text_cols; + FRAME_LINES (f) = new_text_lines; FRAME_TEXT_WIDTH (f) = new_text_width; FRAME_TEXT_HEIGHT (f) = new_text_height; - FRAME_PIXEL_WIDTH (f) = new_pixel_width; - FRAME_PIXEL_HEIGHT (f) = new_pixel_height; - SET_FRAME_COLS (f, new_cols); - SET_FRAME_LINES (f, new_lines); + FRAME_PIXEL_WIDTH (f) = new_native_width; + FRAME_PIXEL_HEIGHT (f) = new_native_height; + FRAME_TOTAL_COLS (f) = FRAME_PIXEL_WIDTH (f) / FRAME_COLUMN_WIDTH (f); + FRAME_TOTAL_LINES (f) = FRAME_PIXEL_HEIGHT (f) / FRAME_LINE_HEIGHT (f); { struct window *w = XWINDOW (FRAME_SELECTED_WINDOW (f)); @@ -749,18 +891,18 @@ adjust_frame_size (struct frame *f, int new_width, int new_height, int inhibit, w->cursor.vpos = w->cursor.y = 0; } - /* Sanitize window sizes. */ - sanitize_window_sizes (Qt); - sanitize_window_sizes (Qnil); - adjust_frame_glyphs (f); calculate_costs (f); SET_FRAME_GARBAGED (f); + /* We now say here that F was resized instead of using the old + condition below. Some resizing must have taken place and if it was + only shifting the root window's position (paranoia?). */ + f->resized_p = true; - /* A frame was "resized" if one of its pixelsizes changed, even if its - X window wasn't resized at all. */ - f->resized_p = (new_pixel_width != old_pixel_width - || new_pixel_height != old_pixel_height); +/** /\* A frame was "resized" if its native size changed, even if its X **/ +/** window wasn't resized at all. *\/ **/ +/** f->resized_p = (new_native_width != old_native_width **/ +/** || new_native_height != old_native_height); **/ unblock_input (); @@ -771,8 +913,8 @@ adjust_frame_size (struct frame *f, int new_width, int new_height, int inhibit, FOR_EACH_FRAME (frames, frame1) if (FRAME_PARENT_FRAME (XFRAME (frame1)) == f) - keep_ratio (XFRAME (frame1), f, old_pixel_width, old_pixel_height, - new_pixel_width, new_pixel_height); + keep_ratio (XFRAME (frame1), f, old_native_width, old_native_height, + new_native_width, new_native_height); } #endif } @@ -782,7 +924,8 @@ adjust_frame_size (struct frame *f, int new_width, int new_height, int inhibit, static struct frame * allocate_frame (void) { - return ALLOCATE_ZEROED_PSEUDOVECTOR (struct frame, face_cache, PVEC_FRAME); + return ALLOCATE_ZEROED_PSEUDOVECTOR (struct frame, tool_bar_items, + PVEC_FRAME); } struct frame * @@ -810,14 +953,18 @@ make_frame (bool mini_p) f->wants_modeline = true; f->redisplay = true; f->garbaged = true; - f->can_x_set_window_size = false; + f->can_set_window_size = false; f->after_make_frame = false; f->inhibit_horizontal_resize = false; f->inhibit_vertical_resize = false; + f->tab_bar_redisplayed = false; + f->tab_bar_resized = false; f->tool_bar_redisplayed = false; f->tool_bar_resized = false; f->column_width = 1; /* !FRAME_WINDOW_P value. */ f->line_height = 1; /* !FRAME_WINDOW_P value. */ + f->new_width = -1; + f->new_height = -1; #ifdef HAVE_WINDOW_SYSTEM f->vertical_scroll_bar_type = vertical_scroll_bar_none; f->horizontal_scroll_bars = false; @@ -831,15 +978,21 @@ make_frame (bool mini_p) f->no_focus_on_map = false; f->no_accept_focus = false; f->z_group = z_group_none; -#if ! defined (USE_GTK) && ! defined (HAVE_NS) + f->tooltip = false; + f->was_invisible = false; + f->child_frame_border_width = -1; + f->last_tab_bar_item = -1; +#ifndef HAVE_EXT_TOOL_BAR f->last_tool_bar_item = -1; #endif #ifdef NS_IMPL_COCOA - f->ns_appearance = ns_appearance_aqua; + f->ns_appearance = ns_appearance_system_default; f->ns_transparent_titlebar = false; #endif #endif - + f->select_mini_window_flag = false; + /* This one should never be zero. */ + f->change_stamp = 1; root_window = make_window (); rw = XWINDOW (root_window); if (mini_p) @@ -862,20 +1015,21 @@ make_frame (bool mini_p) wset_frame (rw, frame); - /* 10 is arbitrary, - just so that there is "something there." + /* 80/25 is arbitrary, just so that there is "something there." Correct size will be set up later with adjust_frame_size. */ + FRAME_COLS (f) = FRAME_TOTAL_COLS (f) = rw->total_cols = 80; + FRAME_TEXT_WIDTH (f) = FRAME_PIXEL_WIDTH (f) = rw->pixel_width + = 80 * FRAME_COLUMN_WIDTH (f); + FRAME_LINES (f) = FRAME_TOTAL_LINES (f) = 25; + FRAME_TEXT_HEIGHT (f) = FRAME_PIXEL_HEIGHT (f) = 25 * FRAME_LINE_HEIGHT (f); - SET_FRAME_COLS (f, 10); - SET_FRAME_LINES (f, 10); - SET_FRAME_WIDTH (f, FRAME_COLS (f) * FRAME_COLUMN_WIDTH (f)); - SET_FRAME_HEIGHT (f, FRAME_LINES (f) * FRAME_LINE_HEIGHT (f)); - - rw->total_cols = 10; - rw->pixel_width = rw->total_cols * FRAME_COLUMN_WIDTH (f); - rw->total_lines = mini_p ? 9 : 10; + rw->total_lines = FRAME_LINES (f) - (mini_p ? 1 : 0); rw->pixel_height = rw->total_lines * FRAME_LINE_HEIGHT (f); + fset_face_hash_table + (f, make_hash_table (hashtest_eq, DEFAULT_HASH_SIZE, DEFAULT_REHASH_SIZE, + DEFAULT_REHASH_THRESHOLD, Qnil, false)); + if (mini_p) { mw->top_line = rw->total_lines; @@ -905,15 +1059,11 @@ make_frame (bool mini_p) } if (mini_p) - { - set_window_buffer (mini_window, - (NILP (Vminibuffer_list) - ? get_minibuffer (0) - : Fcar (Vminibuffer_list)), - 0, 0); - /* No horizontal scroll bars in minibuffers. */ - wset_horizontal_scroll_bar (mw, Qnil); - } + set_window_buffer (mini_window, + (NILP (Vminibuffer_list) + ? get_minibuffer (0) + : Fcar (Vminibuffer_list)), + 0, 0); fset_root_window (f, root_window); fset_selected_window (f, root_window); @@ -1022,7 +1172,7 @@ make_minibuffer_frame (void) /* Construct a frame that refers to a terminal. */ -static printmax_t tty_frame_count; +static intmax_t tty_frame_count; struct frame * make_initial_frame (void) @@ -1032,14 +1182,11 @@ make_initial_frame (void) Lisp_Object frame; eassert (initial_kboard); - - /* The first call must initialize Vframe_list. */ - if (! (NILP (Vframe_list) || CONSP (Vframe_list))) - Vframe_list = Qnil; + eassert (NILP (Vframe_list) || CONSP (Vframe_list)); terminal = init_initial_terminal (); - f = make_frame (1); + f = make_frame (true); XSETFRAME (frame, f); Vframe_list = Fcons (frame, Vframe_list); @@ -1052,7 +1199,6 @@ make_initial_frame (void) f->output_method = terminal->type; f->terminal = terminal; f->terminal->reference_count++; - f->output_data.nothing = 0; FRAME_FOREGROUND_PIXEL (f) = FACE_TTY_DEFAULT_FG_COLOR; FRAME_BACKGROUND_PIXEL (f) = FACE_TTY_DEFAULT_BG_COLOR; @@ -1063,7 +1209,10 @@ make_initial_frame (void) #endif /* The default value of menu-bar-mode is t. */ - set_menu_bar_lines (f, make_number (1), Qnil); + set_menu_bar_lines (f, make_fixnum (1), Qnil); + + /* The default value of tab-bar-mode is nil. */ + set_tab_bar_lines (f, make_fixnum (0), Qnil); /* Allocate glyph matrices. */ adjust_frame_glyphs (f); @@ -1073,7 +1222,7 @@ make_initial_frame (void) last_nonminibuf_frame = f; - f->can_x_set_window_size = true; + f->can_set_window_size = true; f->after_make_frame = true; return f; @@ -1085,7 +1234,7 @@ make_terminal_frame (struct terminal *terminal) { register struct frame *f; Lisp_Object frame; - char name[sizeof "F" + INT_STRLEN_BOUND (printmax_t)]; + char name[sizeof "F" + INT_STRLEN_BOUND (tty_frame_count)]; if (!terminal->name) error ("Terminal is not live, can't create new frames on it"); @@ -1095,13 +1244,14 @@ make_terminal_frame (struct terminal *terminal) XSETFRAME (frame, f); Vframe_list = Fcons (frame, Vframe_list); - fset_name (f, make_formatted_string (name, "F%"pMd, ++tty_frame_count)); + fset_name (f, make_formatted_string (name, "F%"PRIdMAX, ++tty_frame_count)); SET_FRAME_VISIBLE (f, 1); f->terminal = terminal; f->terminal->reference_count++; #ifdef MSDOS + f->output_data.tty = &the_only_tty_output; f->output_data.tty->display_info = &the_only_display_info; if (!inhibit_window_system && (!FRAMEP (selected_frame) || !FRAME_LIVE_P (XFRAME (selected_frame)) @@ -1122,9 +1272,13 @@ make_terminal_frame (struct terminal *terminal) #endif FRAME_MENU_BAR_LINES (f) = NILP (Vmenu_bar_mode) ? 0 : 1; - FRAME_LINES (f) = FRAME_LINES (f) - FRAME_MENU_BAR_LINES (f); + FRAME_TAB_BAR_LINES (f) = NILP (Vtab_bar_mode) ? 0 : 1; + FRAME_LINES (f) = FRAME_LINES (f) - FRAME_MENU_BAR_LINES (f) + - FRAME_TAB_BAR_LINES (f); FRAME_MENU_BAR_HEIGHT (f) = FRAME_MENU_BAR_LINES (f) * FRAME_LINE_HEIGHT (f); - FRAME_TEXT_HEIGHT (f) = FRAME_TEXT_HEIGHT (f) - FRAME_MENU_BAR_HEIGHT (f); + FRAME_TAB_BAR_HEIGHT (f) = FRAME_TAB_BAR_LINES (f) * FRAME_LINE_HEIGHT (f); + FRAME_TEXT_HEIGHT (f) = FRAME_TEXT_HEIGHT (f) - FRAME_MENU_BAR_HEIGHT (f) + - FRAME_TAB_BAR_HEIGHT (f); /* Set the top frame to the newly created frame. */ if (FRAMEP (FRAME_TTY (f)->top_frame) @@ -1184,7 +1338,7 @@ affects all frames on the same terminal device. */) { struct frame *f; struct terminal *t = NULL; - Lisp_Object frame, tem; + Lisp_Object frame; struct frame *sf = SELECTED_FRAME (); #ifdef MSDOS @@ -1246,7 +1400,8 @@ affects all frames on the same terminal device. */) { int width, height; get_tty_size (fileno (FRAME_TTY (f)->input), &width, &height); - adjust_frame_size (f, width, height - FRAME_MENU_BAR_LINES (f), + /* With INHIBIT 5 pass correct text height to adjust_frame_size. */ + adjust_frame_size (f, width, height - FRAME_TOP_MARGIN (f), 5, 0, Qterminal_frame); } @@ -1259,22 +1414,25 @@ affects all frames on the same terminal device. */) (t->display_info.tty->name ? build_string (t->display_info.tty->name) : Qnil)); + + /* Make the frame face hash be frame-specific, so that each + frame could change its face definitions independently. */ + fset_face_hash_table (f, Fcopy_hash_table (sf->face_hash_table)); + /* Simple copy_hash_table isn't enough, because we need the contents of + the vectors which are the values in face_hash_table to + be copied as well. */ + ptrdiff_t idx = 0; + struct Lisp_Hash_Table *table = XHASH_TABLE (f->face_hash_table); + for (idx = 0; idx < table->count; ++idx) + set_hash_value_slot (table, idx, Fcopy_sequence (HASH_VALUE (table, idx))); + /* On terminal frames the `minibuffer' frame parameter is always virtually t. Avoid that a different value in parms causes complaints, see Bug#24758. */ store_in_alist (&parms, Qminibuffer, Qt); Fmodify_frame_parameters (frame, parms); - /* Make the frame face alist be frame-specific, so that each - frame could change its face definitions independently. */ - fset_face_alist (f, Fcopy_alist (sf->face_alist)); - /* Simple Fcopy_alist isn't enough, because we need the contents of - the vectors which are the CDRs of associations in face_alist to - be copied as well. */ - for (tem = f->face_alist; CONSP (tem); tem = XCDR (tem)) - XSETCDR (XCAR (tem), Fcopy_sequence (XCDR (XCAR (tem)))); - - f->can_x_set_window_size = true; + f->can_set_window_size = true; f->after_make_frame = true; return frame; @@ -1286,10 +1444,6 @@ affects all frames on the same terminal device. */) If FRAME is a switch-frame event `(switch-frame FRAME1)', use FRAME1 as frame. - If TRACK is non-zero and the frame that currently has the focus - redirects its focus to the selected frame, redirect that focused - frame's focus to FRAME instead. - FOR_DELETION non-zero means that the selected frame is being deleted, which includes the possibility that the frame's terminal is dead. @@ -1297,7 +1451,7 @@ affects all frames on the same terminal device. */) The value of NORECORD is passed as argument to Fselect_window. */ Lisp_Object -do_switch_frame (Lisp_Object frame, int track, int for_deletion, Lisp_Object norecord) +do_switch_frame (Lisp_Object frame, int for_deletion, Lisp_Object norecord) { struct frame *sf = SELECTED_FRAME (), *f; @@ -1313,60 +1467,12 @@ do_switch_frame (Lisp_Object frame, int track, int for_deletion, Lisp_Object nor especially when deleting the initial frame during startup. */ CHECK_FRAME (frame); f = XFRAME (frame); - if (!FRAME_LIVE_P (f)) + /* Silently ignore dead and tooltip frames (Bug#47207). */ + if (!FRAME_LIVE_P (f) || FRAME_TOOLTIP_P (f)) return Qnil; else if (f == sf) return frame; - /* If a frame's focus has been redirected toward the currently - selected frame, we should change the redirection to point to the - newly selected frame. This means that if the focus is redirected - from a minibufferless frame to a surrogate minibuffer frame, we - can use `other-window' to switch between all the frames using - that minibuffer frame, and the focus redirection will follow us - around. */ -#if 0 - /* This is too greedy; it causes inappropriate focus redirection - that's hard to get rid of. */ - if (track) - { - Lisp_Object tail; - - for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail)) - { - Lisp_Object focus; - - if (!FRAMEP (XCAR (tail))) - emacs_abort (); - - focus = FRAME_FOCUS_FRAME (XFRAME (XCAR (tail))); - - if (FRAMEP (focus) && XFRAME (focus) == SELECTED_FRAME ()) - Fredirect_frame_focus (XCAR (tail), frame); - } - } -#else /* ! 0 */ - /* Instead, apply it only to the frame we're pointing to. */ -#ifdef HAVE_WINDOW_SYSTEM - if (track && FRAME_WINDOW_P (f)) - { - Lisp_Object focus, xfocus; - - xfocus = x_get_focus_frame (f); - if (FRAMEP (xfocus)) - { - focus = FRAME_FOCUS_FRAME (XFRAME (xfocus)); - if ((FRAMEP (focus) && XFRAME (focus) == SELECTED_FRAME ()) - /* Redirect frame focus also when FRAME has its minibuffer - window on the selected frame (see Bug#24500). */ - || (NILP (focus) - && EQ (FRAME_MINIBUF_WINDOW (f), sf->selected_window))) - Fredirect_frame_focus (xfocus, frame); - } - } -#endif /* HAVE_X_WINDOWS */ -#endif /* ! 0 */ - if (!for_deletion && FRAME_HAS_MINIBUF_P (sf)) resize_mini_window (XWINDOW (FRAME_MINIBUF_WINDOW (sf)), 1); @@ -1395,16 +1501,39 @@ do_switch_frame (Lisp_Object frame, int track, int for_deletion, Lisp_Object nor tty->top_frame = frame; } + sf->select_mini_window_flag = MINI_WINDOW_P (XWINDOW (sf->selected_window)); + selected_frame = frame; + + move_minibuffers_onto_frame (sf, for_deletion); + + if (f->select_mini_window_flag + && !NILP (Fminibufferp (XWINDOW (f->minibuffer_window)->contents, Qt))) + f->selected_window = f->minibuffer_window; + f->select_mini_window_flag = false; + if (! FRAME_MINIBUF_ONLY_P (XFRAME (selected_frame))) last_nonminibuf_frame = XFRAME (selected_frame); + /* If the selected window in the target frame is its mini-window, we move + to a different window, the most recently used one, unless there is a + valid active minibuffer in the mini-window. */ + if (EQ (f->selected_window, f->minibuffer_window) + /* The following test might fail if the mini-window contains a + non-active minibuffer. */ + && NILP (Fminibufferp (XWINDOW (f->minibuffer_window)->contents, Qt))) + { + Lisp_Object w = call1 (Qget_mru_window, frame); + if (WINDOW_LIVE_P (w)) /* W can be nil in minibuffer-only frames. */ + Fset_frame_selected_window (frame, w, Qnil); + } + Fselect_window (f->selected_window, norecord); /* We want to make sure that the next event generates a frame-switch event to the appropriate frame. This seems kludgy to me, but before you take it out, make sure that evaluating something like - (select-window (frame-root-window (new-frame))) doesn't end up + (select-window (frame-root-window (make-frame))) doesn't end up with your typing being interpreted in the new frame instead of the one you're actually typing in. */ #ifdef HAVE_WINDOW_SYSTEM @@ -1432,29 +1561,32 @@ redisplay will display FRAME. This function returns FRAME, or nil if FRAME has been deleted. */) (Lisp_Object frame, Lisp_Object norecord) { - return do_switch_frame (frame, 1, 0, norecord); + struct frame *f; + + CHECK_LIVE_FRAME (frame); + f = XFRAME (frame); + + if (FRAME_TOOLTIP_P (f)) + /* Do not select a tooltip frame (Bug#47207). */ + error ("Cannot select a tooltip frame"); + else + return do_switch_frame (frame, 0, norecord); } -DEFUN ("handle-switch-frame", Fhandle_switch_frame, Shandle_switch_frame, 1, 1, "^e", +DEFUN ("handle-switch-frame", Fhandle_switch_frame, + Shandle_switch_frame, 1, 1, "^e", doc: /* Handle a switch-frame event EVENT. Switch-frame events are usually bound to this function. -A switch-frame event tells Emacs that the window manager has requested -that the user's events be directed to the frame mentioned in the event. -This function selects the selected window of the frame of EVENT. - -If EVENT is frame object, handle it as if it were a switch-frame event -to that frame. */) +A switch-frame event is an event Emacs sends itself to +indicate that input is arriving in a new frame. It does not +necessarily represent user-visible input focus. */) (Lisp_Object event) { - Lisp_Object value; - /* Preserve prefix arg that the command loop just cleared. */ kset_prefix_arg (current_kboard, Vcurrent_prefix_arg); run_hook (Qmouse_leave_buffer_hook); - /* `switch-frame' implies a focus in. */ - value = do_switch_frame (event, 0, 0, Qnil); - call1 (intern ("handle-focus-in"), event); - return value; + + return do_switch_frame (event, 0, Qnil); } DEFUN ("selected-frame", Fselected_frame, Sselected_frame, 0, 0, 0, @@ -1463,19 +1595,36 @@ DEFUN ("selected-frame", Fselected_frame, Sselected_frame, 0, 0, 0, { return selected_frame; } + +DEFUN ("old-selected-frame", Fold_selected_frame, + Sold_selected_frame, 0, 0, 0, + doc: /* Return the old selected FRAME. +FRAME must be a live frame and defaults to the selected one. + +The return value is the frame selected the last time window change +functions were run. */) + (void) +{ + return old_selected_frame; +} DEFUN ("frame-list", Fframe_list, Sframe_list, 0, 0, 0, - doc: /* Return a list of all live frames. */) + doc: /* Return a list of all live frames. +The return value does not include any tooltip frame. */) (void) { - Lisp_Object frames; - frames = Fcopy_sequence (Vframe_list); #ifdef HAVE_WINDOW_SYSTEM - if (FRAMEP (tip_frame)) - frames = Fdelq (tip_frame, frames); -#endif - return frames; + Lisp_Object list = Qnil, tail, frame; + + FOR_EACH_FRAME (tail, frame) + if (!FRAME_TOOLTIP_P (XFRAME (frame))) + list = Fcons (frame, list); + /* Reverse list for consistency with the !HAVE_WINDOW_SYSTEM case. */ + return Fnreverse (list); +#else /* !HAVE_WINDOW_SYSTEM */ + return Fcopy_sequence (Vframe_list); +#endif /* HAVE_WINDOW_SYSTEM */ } DEFUN ("frame-parent", Fframe_parent, Sframe_parent, @@ -1584,7 +1733,7 @@ candidate_frame (Lisp_Object candidate, Lisp_Object frame, Lisp_Object minibuf) FRAME_FOCUS_FRAME (c))) return candidate; } - else if (INTEGERP (minibuf) && XINT (minibuf) == 0) + else if (FIXNUMP (minibuf) && XFIXNUM (minibuf) == 0) { if (FRAME_VISIBLE_P (c) || FRAME_ICONIFIED_P (c)) return candidate; @@ -1603,6 +1752,8 @@ next_frame (Lisp_Object frame, Lisp_Object minibuf) Lisp_Object f, tail; int passed = 0; + eassume (CONSP (Vframe_list)); + while (passed < 2) FOR_EACH_FRAME (tail, f) { @@ -1625,6 +1776,8 @@ prev_frame (Lisp_Object frame, Lisp_Object minibuf) { Lisp_Object f, tail, prev = Qnil; + eassume (CONSP (Vframe_list)); + FOR_EACH_FRAME (tail, f) { if (EQ (frame, f) && !NILP (prev)) @@ -1649,15 +1802,20 @@ prev_frame (Lisp_Object frame, Lisp_Object minibuf) DEFUN ("next-frame", Fnext_frame, Snext_frame, 0, 2, 0, doc: /* Return the next frame in the frame list after FRAME. -It considers only frames on the same terminal as FRAME. -By default, skip minibuffer-only frames. -If omitted, FRAME defaults to the selected frame. -If optional argument MINIFRAME is nil, exclude minibuffer-only frames. -If MINIFRAME is a window, include only its own frame -and any frame now using that window as the minibuffer. -If MINIFRAME is `visible', include all visible frames. -If MINIFRAME is 0, include all visible and iconified frames. -Otherwise, include all frames. */) +Only frames on the same terminal as FRAME are included in the list +of candidate frames. If omitted, FRAME defaults to the selected frame. + +If MINIFRAME is nil (the default), include all frames except +minibuffer-only frames. + +If MINIFRAME is a window, include only its own frame and any frame now +using that window as the minibuffer. + +If MINIFRAME is `visible', include only visible frames. + +If MINIFRAME is 0, include only visible and iconified frames. + +If MINIFRAME is any other value, include all frames. */) (Lisp_Object frame, Lisp_Object miniframe) { if (NILP (frame)) @@ -1702,7 +1860,8 @@ DEFUN ("last-nonminibuffer-frame", Flast_nonminibuf_frame, * other_frames: * * Return true if there exists at least one visible or iconified frame - * but F. Return false otherwise. + * but F. Tooltip frames do not qualify as candidates. Return false + * if no such frame exists. * * INVISIBLE true means we are called from make_frame_invisible where * such a frame must be visible or iconified. INVISIBLE nil means we @@ -1716,7 +1875,6 @@ static bool other_frames (struct frame *f, bool invisible, bool force) { Lisp_Object frames, frame, frame1; - struct frame *f1; Lisp_Object minibuffer_window = FRAME_MINIBUF_WINDOW (f); XSETFRAME (frame, f); @@ -1726,7 +1884,8 @@ other_frames (struct frame *f, bool invisible, bool force) FOR_EACH_FRAME (frames, frame1) { - f1 = XFRAME (frame1); + struct frame *f1 = XFRAME (frame1); + if (f != f1) { /* Verify that we can still talk to the frame's X window, and @@ -1735,7 +1894,7 @@ other_frames (struct frame *f, bool invisible, bool force) if (FRAME_WINDOW_P (f1)) x_sync (f1); #endif - if (NILP (Fframe_parameter (frame1, Qtooltip)) + if (!FRAME_TOOLTIP_P (f1) /* Tooltips and child frames count neither for invisibility nor for deletions. */ && !FRAME_PARENT_FRAME (f1) @@ -1757,52 +1916,6 @@ other_frames (struct frame *f, bool invisible, bool force) return false; } -/* Make sure that minibuf_window doesn't refer to FRAME's minibuffer - window. Preferably use the selected frame's minibuffer window - instead. If the selected frame doesn't have one, get some other - frame's minibuffer window. SELECT non-zero means select the new - minibuffer window. */ -static void -check_minibuf_window (Lisp_Object frame, int select) -{ - struct frame *f = decode_live_frame (frame); - - XSETFRAME (frame, f); - - if (WINDOWP (minibuf_window) && EQ (f->minibuffer_window, minibuf_window)) - { - Lisp_Object frames, this, window = make_number (0); - - if (!EQ (frame, selected_frame) - && FRAME_HAS_MINIBUF_P (XFRAME (selected_frame))) - window = FRAME_MINIBUF_WINDOW (XFRAME (selected_frame)); - else - FOR_EACH_FRAME (frames, this) - { - if (!EQ (this, frame) && FRAME_HAS_MINIBUF_P (XFRAME (this))) - { - window = FRAME_MINIBUF_WINDOW (XFRAME (this)); - break; - } - } - - /* Don't abort if no window was found (Bug#15247). */ - if (WINDOWP (window)) - { - /* Use set_window_buffer instead of Fset_window_buffer (see - discussion of bug#11984, bug#12025, bug#12026). */ - set_window_buffer (window, XWINDOW (minibuf_window)->contents, 0, 0); - minibuf_window = window; - - /* SELECT non-zero usually means that FRAME's minibuffer - window was selected; select the new one. */ - if (select) - Fselect_window (minibuf_window, Qnil); - } - } -} - - /** * delete_frame: * @@ -1817,8 +1930,12 @@ delete_frame (Lisp_Object frame, Lisp_Object force) struct frame *sf; struct kboard *kb; Lisp_Object frames, frame1; - int minibuffer_selected, is_tooltip_frame; + int is_tooltip_frame; bool nochild = !FRAME_PARENT_FRAME (f); + Lisp_Object minibuffer_child_frame = Qnil; +#ifdef HAVE_X_WINDOWS + specpdl_ref ref; +#endif if (!FRAME_LIVE_P (f)) return Qnil; @@ -1829,19 +1946,48 @@ delete_frame (Lisp_Object frame, Lisp_Object force) else error ("Attempt to delete the only frame"); } +#ifdef HAVE_X_WINDOWS + else if ((x_dnd_in_progress && f == x_dnd_frame) + || (x_dnd_waiting_for_finish && f == x_dnd_finish_frame)) + error ("Attempt to delete the drop source frame"); +#endif +#ifdef HAVE_HAIKU + else if (f == haiku_dnd_frame) + error ("Attempt to delete the drop source frame"); +#endif XSETFRAME (frame, f); /* Softly delete all frames with this frame as their parent frame or as their `delete-before' frame parameter value. */ FOR_EACH_FRAME (frames, frame1) - if (FRAME_PARENT_FRAME (XFRAME (frame1)) == f + { + struct frame *f1 = XFRAME (frame1); + + if (EQ (frame1, frame) || FRAME_TOOLTIP_P (f1)) + continue; + else if (FRAME_PARENT_FRAME (f1) == f) + { + if (FRAME_HAS_MINIBUF_P (f1) && !FRAME_HAS_MINIBUF_P (f) + && EQ (FRAME_MINIBUF_WINDOW (f), FRAME_MINIBUF_WINDOW (f1))) + /* frame1 owns frame's minibuffer window so we must not + delete it here to avoid a surrogate minibuffer error. + Unparent frame1 and make it a top-level frame. */ + { + Fmodify_frame_parameters + (frame1, Fcons (Fcons (Qparent_frame, Qnil), Qnil)); + minibuffer_child_frame = frame1; + } + else + delete_frame (frame1, Qnil); + } + else if (nochild + && EQ (get_frame_param (XFRAME (frame1), Qdelete_before), frame)) /* Process `delete-before' parameter iff FRAME is not a child frame. This avoids that we enter an infinite chain of mixed dependencies. */ - || (nochild - && EQ (get_frame_param (XFRAME (frame1), Qdelete_before), frame))) - delete_frame (frame1, Qnil); + delete_frame (frame1, Qnil); + } /* Does this frame have a minibuffer, and is it the surrogate minibuffer for any other frame? */ @@ -1868,7 +2014,7 @@ delete_frame (Lisp_Object frame, Lisp_Object force) } } - is_tooltip_frame = !NILP (Fframe_parameter (frame, Qtooltip)); + is_tooltip_frame = FRAME_TOOLTIP_P (f); /* Run `delete-frame-functions' unless FORCE is `noelisp' or frame is a tooltip. FORCE is set to `noelisp' when handling @@ -1904,35 +2050,43 @@ delete_frame (Lisp_Object frame, Lisp_Object force) /* At this point, we are committed to deleting the frame. There is no more chance for errors to prevent it. */ - minibuffer_selected = EQ (minibuf_window, selected_window); sf = SELECTED_FRAME (); /* Don't let the frame remain selected. */ if (f == sf) { Lisp_Object tail; + Lisp_Object frame1 UNINIT; /* This line works around GCC bug 85563. */ + eassume (CONSP (Vframe_list)); /* Look for another visible frame on the same terminal. Do not call next_frame here because it may loop forever. See https://debbugs.gnu.org/cgi/bugreport.cgi?bug=15025. */ FOR_EACH_FRAME (tail, frame1) - if (!EQ (frame, frame1) - && (FRAME_TERMINAL (XFRAME (frame)) - == FRAME_TERMINAL (XFRAME (frame1))) - && FRAME_VISIBLE_P (XFRAME (frame1))) - break; + { + struct frame *f1 = XFRAME (frame1); + + if (!EQ (frame, frame1) + && !FRAME_TOOLTIP_P (f1) + && FRAME_TERMINAL (f) == FRAME_TERMINAL (f1) + && FRAME_VISIBLE_P (f1)) + break; + } /* If there is none, find *some* other frame. */ if (NILP (frame1) || EQ (frame1, frame)) { FOR_EACH_FRAME (tail, frame1) { - if (! EQ (frame, frame1) && FRAME_LIVE_P (XFRAME (frame1))) + struct frame *f1 = XFRAME (frame1); + + if (!EQ (frame, frame1) + && FRAME_LIVE_P (f1) + && !FRAME_TOOLTIP_P (f1)) { - /* Do not change a text terminal's top-frame. */ - struct frame *f1 = XFRAME (frame1); if (FRAME_TERMCAP_P (f1) || FRAME_MSDOS_P (f1)) { Lisp_Object top_frame = FRAME_TTY (f1)->top_frame; + if (!EQ (top_frame, frame)) frame1 = top_frame; } @@ -1950,12 +2104,13 @@ delete_frame (Lisp_Object frame, Lisp_Object force) Fraise_frame (frame1); #endif - do_switch_frame (frame1, 0, 1, Qnil); + do_switch_frame (frame1, 1, Qnil); sf = SELECTED_FRAME (); } - - /* Don't allow minibuf_window to remain on a deleted frame. */ - check_minibuf_window (frame, minibuffer_selected); + else + /* Ensure any minibuffers on FRAME are moved onto the selected + frame. */ + move_minibuffers_onto_frame (f, true); /* Don't let echo_area_window to remain on a deleted frame. */ if (EQ (f->minibuffer_window, echo_area_window)) @@ -1964,7 +2119,29 @@ delete_frame (Lisp_Object frame, Lisp_Object force) /* Clear any X selections for this frame. */ #ifdef HAVE_X_WINDOWS if (FRAME_X_P (f)) - x_clear_frame_selections (f); + { + /* Don't preserve selections when a display is going away, since + that sends stuff down the wire. */ + + ref = SPECPDL_INDEX (); + + if (EQ (force, Qnoelisp)) + specbind (Qx_auto_preserve_selections, Qnil); + + x_clear_frame_selections (f); + unbind_to (ref, Qnil); + } +#endif + +#ifdef HAVE_PGTK + if (FRAME_PGTK_P (f)) + { + /* Do special selection events now, in case the window gets + destroyed by this deletion. Does this run Lisp code? */ + swallow_events (false); + + pgtk_clear_frame_selections (f); + } #endif /* Free glyphs. @@ -2019,7 +2196,6 @@ delete_frame (Lisp_Object frame, Lisp_Object force) if (FRAME_TERMINAL (f)->delete_frame_hook) (*FRAME_TERMINAL (f)->delete_frame_hook) (f); terminal = FRAME_TERMINAL (f); - f->output_data.nothing = 0; f->terminal = 0; /* Now the frame is dead. */ unblock_input (); @@ -2029,12 +2205,13 @@ delete_frame (Lisp_Object frame, Lisp_Object force) #if defined (USE_X_TOOLKIT) || defined (USE_GTK) /* FIXME: Deleting the terminal crashes emacs because of a GTK bug. - https://lists.gnu.org/archive/html/emacs-devel/2011-10/msg00363.html */ + https://lists.gnu.org/r/emacs-devel/2011-10/msg00363.html */ /* Since a similar behavior was observed on the Lucid and Motif builds (see Bug#5802, Bug#21509, Bug#23499, Bug#27816), we now don't delete the terminal for these builds either. */ - if (terminal->reference_count == 0 && terminal->type == output_x_window) + if (terminal->reference_count == 0 && + (terminal->type == output_x_window || terminal->type == output_pgtk)) terminal->reference_count = 1; #endif /* USE_X_TOOLKIT || USE_GTK */ if (terminal->reference_count == 0) @@ -2097,18 +2274,27 @@ delete_frame (Lisp_Object frame, Lisp_Object force) { struct frame *f1 = XFRAME (frame1); - /* Consider only frames on the same kboard - and only those with minibuffers. */ - if (kb == FRAME_KBOARD (f1) - && FRAME_HAS_MINIBUF_P (f1)) + /* Set frame_on_same_kboard to frame1 if it is on the same + keyboard. Set frame_with_minibuf to frame1 if it also + has a minibuffer. Leave the loop immediately if frame1 + is also minibuffer-only. + + Emacs 26 does _not_ set frame_on_same_kboard here when it + finds a minibuffer-only frame and subsequently fails to + set default_minibuffer_frame below. Not a great deal and + never noticed since make_frame_without_minibuffer creates + a new minibuffer frame in that case (which can be a minor + annoyance though). To consider for Emacs 26.3. */ + if (kb == FRAME_KBOARD (f1)) { - frame_with_minibuf = frame1; - if (FRAME_MINIBUF_ONLY_P (f1)) - break; + frame_on_same_kboard = frame1; + if (FRAME_HAS_MINIBUF_P (f1)) + { + frame_with_minibuf = frame1; + if (FRAME_MINIBUF_ONLY_P (f1)) + break; + } } - - if (kb == FRAME_KBOARD (f1)) - frame_on_same_kboard = frame1; } if (!NILP (frame_on_same_kboard)) @@ -2129,17 +2315,70 @@ delete_frame (Lisp_Object frame, Lisp_Object force) kset_default_minibuffer_frame (kb, Qnil); } - /* Cause frame titles to update--necessary if we now have just one frame. */ + /* Cause frame titles to update--necessary if we now have just one + frame. */ if (!is_tooltip_frame) update_mode_lines = 15; + /* Now run the post-deletion hooks. */ + if (NILP (Vrun_hooks) || is_tooltip_frame) + ; + else if (EQ (force, Qnoelisp)) + pending_funcalls + = Fcons (list3 (Qrun_hook_with_args, Qafter_delete_frame_functions, frame), + pending_funcalls); + else + safe_call2 (Qrun_hook_with_args, Qafter_delete_frame_functions, frame); + + if (!NILP (minibuffer_child_frame)) + /* If minibuffer_child_frame is non-nil, it was FRAME's minibuffer + child frame. Delete it unless it's also the minibuffer frame + of another frame in which case we make sure it's visible. */ + { + struct frame *f1 = XFRAME (minibuffer_child_frame); + + if (FRAME_LIVE_P (f1)) + { + Lisp_Object window1 = FRAME_ROOT_WINDOW (f1); + Lisp_Object frame2; + + FOR_EACH_FRAME (frames, frame2) + { + struct frame *f2 = XFRAME (frame2); + + if (EQ (frame2, minibuffer_child_frame) || FRAME_TOOLTIP_P (f2)) + continue; + else if (EQ (FRAME_MINIBUF_WINDOW (f2), window1)) + { + /* minibuffer_child_frame serves as minibuffer frame + for at least one other frame - so make it visible + and quit. */ + if (!FRAME_VISIBLE_P (f1) && !FRAME_ICONIFIED_P (f1)) + Fmake_frame_visible (minibuffer_child_frame); + + return Qnil; + } + } + + /* No other frame found that uses minibuffer_child_frame as + minibuffer frame. If FORCE is Qnoelisp or there are + other visible frames left, delete minibuffer_child_frame + since it presumably was used by FRAME only. */ + if (EQ (force, Qnoelisp) || other_frames (f1, false, !NILP (force))) + delete_frame (minibuffer_child_frame, Qnoelisp); + } + } + return Qnil; } DEFUN ("delete-frame", Fdelete_frame, Sdelete_frame, 0, 2, "", - doc: /* Delete FRAME, permanently eliminating it from use. + doc: /* Delete FRAME, eliminating it from use. FRAME must be a live frame and defaults to the selected one. +When `undelete-frame-mode' is enabled, the 16 most recently deleted +frames can be undeleted with `undelete-frame', which see. + A frame may not be deleted if its minibuffer serves as surrogate minibuffer for another frame. Normally, you may not delete a frame if all other frames are invisible, but if the second optional argument @@ -2257,11 +2496,20 @@ vertical offset, measured in units of the frame's default character size. If Emacs is running on a mouseless terminal or hasn't been programmed to read the mouse position, it returns the selected frame for FRAME and nil for X and Y. -If `mouse-position-function' is non-nil, `mouse-position' calls it, -passing the normal return value to that function as an argument, -and returns whatever that function returns. */) + +FRAME might be nil if `track-mouse' is set to `drag-source'. This +means there is no frame under the mouse. If `mouse-position-function' +is non-nil, `mouse-position' calls it, passing the normal return value +to that function as an argument, and returns whatever that function +returns. */) (void) { + return mouse_position (true); +} + +Lisp_Object +mouse_position (bool call_mouse_position_function) +{ struct frame *f; Lisp_Object lispy_dummy; Lisp_Object x, y, retval; @@ -2280,17 +2528,20 @@ and returns whatever that function returns. */) &time_dummy); } - if (! NILP (x)) + if (! NILP (x) && f) { - int col = XINT (x); - int row = XINT (y); + int col = XFIXNUM (x); + int row = XFIXNUM (y); pixel_to_glyph_coords (f, col, row, &col, &row, NULL, 1); XSETINT (x, col); XSETINT (y, row); } - XSETFRAME (lispy_dummy, f); + if (f) + XSETFRAME (lispy_dummy, f); + else + lispy_dummy = Qnil; retval = Fcons (lispy_dummy, Fcons (x, y)); - if (!NILP (Vmouse_position_function)) + if (call_mouse_position_function && !NILP (Vmouse_position_function)) retval = call1 (Vmouse_position_function, retval); return retval; } @@ -2301,9 +2552,11 @@ DEFUN ("mouse-pixel-position", Fmouse_pixel_position, The position is given in pixel units, where (0, 0) is the upper-left corner of the frame, X is the horizontal offset, and Y is the vertical offset. -If Emacs is running on a mouseless terminal or hasn't been programmed -to read the mouse position, it returns the selected frame for FRAME -and nil for X and Y. */) +FRAME might be nil if `track-mouse' is set to `drag-source'. This +means there is no frame under the mouse. If Emacs is running on a +mouseless terminal or hasn't been programmed to read the mouse +position, it returns the selected frame for FRAME and nil for X and +Y. */) (void) { struct frame *f; @@ -2324,7 +2577,11 @@ and nil for X and Y. */) &time_dummy); } - XSETFRAME (lispy_dummy, f); + if (f) + XSETFRAME (lispy_dummy, f); + else + lispy_dummy = Qnil; + retval = Fcons (lispy_dummy, Fcons (x, y)); if (!NILP (Vmouse_position_function)) retval = call1 (Vmouse_position_function, retval); @@ -2385,30 +2642,34 @@ before calling this function on it, like this. (Lisp_Object frame, Lisp_Object x, Lisp_Object y) { CHECK_LIVE_FRAME (frame); - CHECK_TYPE_RANGED_INTEGER (int, x); - CHECK_TYPE_RANGED_INTEGER (int, y); + int xval = check_integer_range (x, INT_MIN, INT_MAX); + int yval = check_integer_range (y, INT_MIN, INT_MAX); /* I think this should be done with a hook. */ -#ifdef HAVE_WINDOW_SYSTEM if (FRAME_WINDOW_P (XFRAME (frame))) - /* Warping the mouse will cause enternotify and focus events. */ - frame_set_mouse_position (XFRAME (frame), XINT (x), XINT (y)); -#else -#if defined (MSDOS) - if (FRAME_MSDOS_P (XFRAME (frame))) + { +#ifdef HAVE_WINDOW_SYSTEM + /* Warping the mouse will cause enternotify and focus events. */ + frame_set_mouse_position (XFRAME (frame), xval, yval); +#endif /* HAVE_WINDOW_SYSTEM */ + } +#ifdef MSDOS + else if (FRAME_MSDOS_P (XFRAME (frame))) { Fselect_frame (frame, Qnil); - mouse_moveto (XINT (x), XINT (y)); + mouse_moveto (xval, yval); } -#else -#ifdef HAVE_GPM +#endif /* MSDOS */ + else { Fselect_frame (frame, Qnil); - term_mouse_moveto (XINT (x), XINT (y)); +#ifdef HAVE_GPM + term_mouse_moveto (xval, yval); +#else + (void) xval; + (void) yval; +#endif /* HAVE_GPM */ } -#endif -#endif -#endif return Qnil; } @@ -2426,30 +2687,35 @@ before calling this function on it, like this. (Lisp_Object frame, Lisp_Object x, Lisp_Object y) { CHECK_LIVE_FRAME (frame); - CHECK_TYPE_RANGED_INTEGER (int, x); - CHECK_TYPE_RANGED_INTEGER (int, y); + int xval = check_integer_range (x, INT_MIN, INT_MAX); + int yval = check_integer_range (y, INT_MIN, INT_MAX); /* I think this should be done with a hook. */ -#ifdef HAVE_WINDOW_SYSTEM if (FRAME_WINDOW_P (XFRAME (frame))) - /* Warping the mouse will cause enternotify and focus events. */ - frame_set_mouse_pixel_position (XFRAME (frame), XINT (x), XINT (y)); -#else -#if defined (MSDOS) - if (FRAME_MSDOS_P (XFRAME (frame))) + { + /* Warping the mouse will cause enternotify and focus events. */ +#ifdef HAVE_WINDOW_SYSTEM + frame_set_mouse_pixel_position (XFRAME (frame), xval, yval); +#endif /* HAVE_WINDOW_SYSTEM */ + } +#ifdef MSDOS + else if (FRAME_MSDOS_P (XFRAME (frame))) { Fselect_frame (frame, Qnil); - mouse_moveto (XINT (x), XINT (y)); + mouse_moveto (xval, yval); } -#else -#ifdef HAVE_GPM +#endif /* MSDOS */ + else { Fselect_frame (frame, Qnil); - term_mouse_moveto (XINT (x), XINT (y)); +#ifdef HAVE_GPM + term_mouse_moveto (xval, yval); +#else + (void) xval; + (void) yval; +#endif /* HAVE_GPM */ + } -#endif -#endif -#endif return Qnil; } @@ -2464,11 +2730,8 @@ If omitted, FRAME defaults to the currently selected frame. */) { struct frame *f = decode_live_frame (frame); - /* I think this should be done with a hook. */ -#ifdef HAVE_WINDOW_SYSTEM - if (FRAME_WINDOW_P (f)) - x_make_frame_visible (f); -#endif + if (FRAME_WINDOW_P (f) && FRAME_TERMINAL (f)->frame_visible_invisible_hook) + FRAME_TERMINAL (f)->frame_visible_invisible_hook (f, true); make_frame_visible_1 (f->root_window); @@ -2517,14 +2780,8 @@ displayed in the terminal. */) if (NILP (force) && !other_frames (f, true, false)) error ("Attempt to make invisible the sole visible or iconified frame"); - /* Don't allow minibuf_window to remain on an invisible frame. */ - check_minibuf_window (frame, EQ (minibuf_window, selected_window)); - - /* I think this should be done with a hook. */ -#ifdef HAVE_WINDOW_SYSTEM - if (FRAME_WINDOW_P (f)) - x_make_frame_invisible (f); -#endif + if (FRAME_WINDOW_P (f) && FRAME_TERMINAL (f)->frame_visible_invisible_hook) + FRAME_TERMINAL (f)->frame_visible_invisible_hook (f, false); /* Make menu bar update for the Buffers and Frames menus. */ windows_or_buffers_changed = 16; @@ -2542,6 +2799,7 @@ for how to proceed. */) (Lisp_Object frame) { struct frame *f = decode_live_frame (frame); +#ifdef HAVE_WINDOW_SYSTEM Lisp_Object parent = f->parent_frame; if (!NILP (parent)) @@ -2562,17 +2820,10 @@ for how to proceed. */) return Qnil; } } +#endif /* HAVE_WINDOW_SYSTEM */ - /* Don't allow minibuf_window to remain on an iconified frame. */ - check_minibuf_window (frame, EQ (minibuf_window, selected_window)); - - /* I think this should be done with a hook. */ - if (FRAME_WINDOW_P (f)) - { -#ifdef HAVE_WINDOW_SYSTEM - x_iconify_frame (f); -#endif - } + if (FRAME_WINDOW_P (f) && FRAME_TERMINAL (f)->iconify_frame_hook) + FRAME_TERMINAL (f)->iconify_frame_hook (f); return Qnil; } @@ -2634,7 +2885,7 @@ doesn't support multiple overlapping frames, this function selects FRAME. */) Fmake_frame_visible (frame); if (FRAME_TERMINAL (f)->frame_raise_lower_hook) - (*FRAME_TERMINAL (f)->frame_raise_lower_hook) (f, 1); + (*FRAME_TERMINAL (f)->frame_raise_lower_hook) (f, true); return Qnil; } @@ -2650,7 +2901,7 @@ doesn't support multiple overlapping frames, this function does nothing. */) struct frame *f = decode_live_frame (frame); if (FRAME_TERMINAL (f)->frame_raise_lower_hook) - (*FRAME_TERMINAL (f)->frame_raise_lower_hook) (f, 0); + (*FRAME_TERMINAL (f)->frame_raise_lower_hook) (f, false); return Qnil; } @@ -2719,7 +2970,9 @@ If there is no window system support, this function does nothing. */) (Lisp_Object frame, Lisp_Object noactivate) { #ifdef HAVE_WINDOW_SYSTEM - x_focus_frame (decode_window_system_frame (frame), !NILP (noactivate)); + struct frame *f = decode_window_system_frame (frame); + if (f && FRAME_TERMINAL (f)->focus_frame_hook) + FRAME_TERMINAL (f)->focus_frame_hook (f, !NILP (noactivate)); #endif return Qnil; } @@ -2768,10 +3021,8 @@ frames_discard_buffer (Lisp_Object buffer) void store_in_alist (Lisp_Object *alistptr, Lisp_Object prop, Lisp_Object val) { - register Lisp_Object tem; - - tem = Fassq (prop, *alistptr); - if (EQ (tem, Qnil)) + Lisp_Object tem = Fassq (prop, *alistptr); + if (NILP (tem)) *alistptr = Fcons (Fcons (prop, val), *alistptr); else Fsetcdr (tem, val); @@ -2792,7 +3043,7 @@ frame_name_fnn_p (char *str, ptrdiff_t len) } /* Set the name of the terminal frame. Also used by MSDOS frames. - Modeled after x_set_name which is used for WINDOW frames. */ + Modeled after *_set_name which is used for WINDOW frames. */ static void set_term_frame_name (struct frame *f, Lisp_Object name) @@ -2802,14 +3053,14 @@ set_term_frame_name (struct frame *f, Lisp_Object name) /* If NAME is nil, set the name to F<num>. */ if (NILP (name)) { - char namebuf[sizeof "F" + INT_STRLEN_BOUND (printmax_t)]; + char namebuf[sizeof "F" + INT_STRLEN_BOUND (tty_frame_count)]; /* Check for no change needed in this very common case before we do any consing. */ if (frame_name_fnn_p (SSDATA (f->name), SBYTES (f->name))) return; - name = make_formatted_string (namebuf, "F%"pMd, ++tty_frame_count); + name = make_formatted_string (namebuf, "F%"PRIdMAX, ++tty_frame_count); } else { @@ -2924,6 +3175,13 @@ store_frame_param (struct frame *f, Lisp_Object prop, Lisp_Object val) fset_buried_buffer_list (f, Fnreverse (list)); return; } + else if ((EQ (prop, Qscroll_bar_width) || EQ (prop, Qscroll_bar_height)) + && !NILP (val) && !RANGED_FIXNUMP (1, val, INT_MAX)) + { + Lisp_Object old_val = Fcdr (Fassq (prop, f->param_alist)); + + val = old_val; + } /* The tty color needed to be set before the frame's parameter alist was updated with the new value. This is not true any more, @@ -2935,7 +3193,7 @@ store_frame_param (struct frame *f, Lisp_Object prop, Lisp_Object val) /* Update the frame parameter alist. */ old_alist_elt = Fassq (prop, f->param_alist); - if (EQ (old_alist_elt, Qnil)) + if (NILP (old_alist_elt)) fset_param_alist (f, Fcons (Fcons (prop, val), f->param_alist)); else Fsetcdr (old_alist_elt, val); @@ -2949,7 +3207,9 @@ store_frame_param (struct frame *f, Lisp_Object prop, Lisp_Object val) if (! FRAME_WINDOW_P (f)) { if (EQ (prop, Qmenu_bar_lines)) - set_menu_bar_lines (f, val, make_number (FRAME_MENU_BAR_LINES (f))); + set_menu_bar_lines (f, val, make_fixnum (FRAME_MENU_BAR_LINES (f))); + else if (EQ (prop, Qtab_bar_lines)) + set_tab_bar_lines (f, val, make_fixnum (FRAME_TAB_BAR_LINES (f))); else if (EQ (prop, Qname)) set_term_frame_name (f, val); } @@ -3016,35 +3276,43 @@ If FRAME is omitted or nil, return information on the currently selected frame. : FRAME_W32_P (f) ? "w32term" :"tty")); } + store_in_alist (&alist, Qname, f->name); - height = (f->new_height - ? (f->new_pixelwise - ? (f->new_height / FRAME_LINE_HEIGHT (f)) - : f->new_height) + /* It's questionable whether here we should report the value of + f->new_height (and f->new_width below) but we've done that in the + past, so let's keep it. Note that a value of -1 for either of + these means that no new size was requested. + + But check f->new_size before to make sure that f->new_height and + f->new_width are not ones requested by adjust_frame_size. */ + height = ((f->new_size_p && f->new_height >= 0) + ? f->new_height / FRAME_LINE_HEIGHT (f) : FRAME_LINES (f)); - store_in_alist (&alist, Qheight, make_number (height)); - width = (f->new_width - ? (f->new_pixelwise - ? (f->new_width / FRAME_COLUMN_WIDTH (f)) - : f->new_width) - : FRAME_COLS (f)); - store_in_alist (&alist, Qwidth, make_number (width)); - store_in_alist (&alist, Qmodeline, (FRAME_WANTS_MODELINE_P (f) ? Qt : Qnil)); - store_in_alist (&alist, Qunsplittable, (FRAME_NO_SPLIT_P (f) ? Qt : Qnil)); + store_in_alist (&alist, Qheight, make_fixnum (height)); + width = ((f->new_size_p && f->new_width >= 0) + ? f->new_width / FRAME_COLUMN_WIDTH (f) + : FRAME_COLS(f)); + store_in_alist (&alist, Qwidth, make_fixnum (width)); + + store_in_alist (&alist, Qmodeline, FRAME_WANTS_MODELINE_P (f) ? Qt : Qnil); + store_in_alist (&alist, Qunsplittable, FRAME_NO_SPLIT_P (f) ? Qt : Qnil); store_in_alist (&alist, Qbuffer_list, f->buffer_list); store_in_alist (&alist, Qburied_buffer_list, f->buried_buffer_list); /* I think this should be done with a hook. */ #ifdef HAVE_WINDOW_SYSTEM if (FRAME_WINDOW_P (f)) - x_report_frame_params (f, &alist); + gui_report_frame_params (f, &alist); else #endif { /* This ought to be correct in f->param_alist for an X frame. */ Lisp_Object lines; + XSETFASTINT (lines, FRAME_MENU_BAR_LINES (f)); store_in_alist (&alist, Qmenu_bar_lines, lines); + XSETFASTINT (lines, FRAME_TAB_BAR_LINES (f)); + store_in_alist (&alist, Qtab_bar_lines, lines); } return alist; @@ -3080,7 +3348,7 @@ If FRAME is nil, describe the currently selected frame. */) else if (EQ (parameter, Qline_spacing) && f->extra_line_spacing == 0) /* If this is non-zero, we can't determine whether the user specified an integer or float value without looking through 'param_alist'. */ - value = make_number (0); + value = make_fixnum (0); else if (EQ (parameter, Qfont) && FRAME_X_P (f)) value = FRAME_FONT (f)->props[FONT_NAME_INDEX]; #endif /* HAVE_WINDOW_SYSTEM */ @@ -3143,7 +3411,7 @@ list, but are otherwise ignored. */) /* I think this should be done with a hook. */ #ifdef HAVE_WINDOW_SYSTEM if (FRAME_WINDOW_P (f)) - x_set_frame_parameters (f, alist); + gui_set_frame_parameters (f, alist); else #endif #ifdef MSDOS @@ -3153,7 +3421,7 @@ list, but are otherwise ignored. */) #endif { - EMACS_INT length = XFASTINT (Flength (alist)); + EMACS_INT length = list_length (alist); ptrdiff_t i; Lisp_Object *parms; Lisp_Object *values; @@ -3201,10 +3469,10 @@ For a terminal frame, the value is always 1. */) struct frame *f = decode_any_frame (frame); if (FRAME_WINDOW_P (f)) - return make_number (FRAME_LINE_HEIGHT (f)); + return make_fixnum (FRAME_LINE_HEIGHT (f)); else #endif - return make_number (1); + return make_fixnum (1); } @@ -3220,27 +3488,30 @@ For a terminal screen, the value is always 1. */) struct frame *f = decode_any_frame (frame); if (FRAME_WINDOW_P (f)) - return make_number (FRAME_COLUMN_WIDTH (f)); + return make_fixnum (FRAME_COLUMN_WIDTH (f)); else #endif - return make_number (1); + return make_fixnum (1); } DEFUN ("frame-native-width", Fframe_native_width, Sframe_native_width, 0, 1, 0, doc: /* Return FRAME's native width in pixels. For a terminal frame, the result really gives the width in characters. -If FRAME is omitted or nil, the selected frame is used. */) +If FRAME is omitted or nil, the selected frame is used. + +If you're interested only in the width of the text portion of the +frame, see `frame-text-width' instead. */) (Lisp_Object frame) { struct frame *f = decode_any_frame (frame); #ifdef HAVE_WINDOW_SYSTEM if (FRAME_WINDOW_P (f)) - return make_number (FRAME_PIXEL_WIDTH (f)); + return make_fixnum (FRAME_PIXEL_WIDTH (f)); else #endif - return make_number (FRAME_TOTAL_COLS (f)); + return make_fixnum (FRAME_TOTAL_COLS (f)); } DEFUN ("frame-native-height", Fframe_native_height, @@ -3254,6 +3525,9 @@ minibuffer or echo area), mode line, and header line. It does not include the tool bar or menu bar. With other graphical versions, it may also include the tool bar and the menu bar. +If you're interested only in the height of the text portion of the +frame, see `frame-text-height' instead. + For a text terminal, it includes the menu bar. In this case, the result is really in characters rather than pixels (i.e., is identical to `frame-height'). */) @@ -3263,10 +3537,10 @@ to `frame-height'). */) #ifdef HAVE_WINDOW_SYSTEM if (FRAME_WINDOW_P (f)) - return make_number (FRAME_PIXEL_HEIGHT (f)); + return make_fixnum (FRAME_PIXEL_HEIGHT (f)); else #endif - return make_number (FRAME_TOTAL_LINES (f)); + return make_fixnum (FRAME_TOTAL_LINES (f)); } DEFUN ("tool-bar-pixel-width", Ftool_bar_pixel_width, @@ -3281,96 +3555,129 @@ is used. */) struct frame *f = decode_any_frame (frame); if (FRAME_WINDOW_P (f)) - return make_number (FRAME_TOOLBAR_WIDTH (f)); + return make_fixnum (FRAME_TOOLBAR_WIDTH (f)); #endif - return make_number (0); + return make_fixnum (0); } DEFUN ("frame-text-cols", Fframe_text_cols, Sframe_text_cols, 0, 1, 0, doc: /* Return width in columns of FRAME's text area. */) (Lisp_Object frame) { - return make_number (FRAME_COLS (decode_any_frame (frame))); + return make_fixnum (FRAME_COLS (decode_any_frame (frame))); } DEFUN ("frame-text-lines", Fframe_text_lines, Sframe_text_lines, 0, 1, 0, doc: /* Return height in lines of FRAME's text area. */) (Lisp_Object frame) { - return make_number (FRAME_LINES (decode_any_frame (frame))); + return make_fixnum (FRAME_LINES (decode_any_frame (frame))); } DEFUN ("frame-total-cols", Fframe_total_cols, Sframe_total_cols, 0, 1, 0, doc: /* Return number of total columns of FRAME. */) (Lisp_Object frame) { - return make_number (FRAME_TOTAL_COLS (decode_any_frame (frame))); + return make_fixnum (FRAME_TOTAL_COLS (decode_any_frame (frame))); } DEFUN ("frame-total-lines", Fframe_total_lines, Sframe_total_lines, 0, 1, 0, doc: /* Return number of total lines of FRAME. */) (Lisp_Object frame) { - return make_number (FRAME_TOTAL_LINES (decode_any_frame (frame))); + return make_fixnum (FRAME_TOTAL_LINES (decode_any_frame (frame))); } DEFUN ("frame-text-width", Fframe_text_width, Sframe_text_width, 0, 1, 0, doc: /* Return text area width of FRAME in pixels. */) (Lisp_Object frame) { - return make_number (FRAME_TEXT_WIDTH (decode_any_frame (frame))); + return make_fixnum (FRAME_TEXT_WIDTH (decode_any_frame (frame))); } DEFUN ("frame-text-height", Fframe_text_height, Sframe_text_height, 0, 1, 0, doc: /* Return text area height of FRAME in pixels. */) (Lisp_Object frame) { - return make_number (FRAME_TEXT_HEIGHT (decode_any_frame (frame))); + return make_fixnum (FRAME_TEXT_HEIGHT (decode_any_frame (frame))); } DEFUN ("frame-scroll-bar-width", Fscroll_bar_width, Sscroll_bar_width, 0, 1, 0, doc: /* Return scroll bar width of FRAME in pixels. */) (Lisp_Object frame) { - return make_number (FRAME_SCROLL_BAR_AREA_WIDTH (decode_any_frame (frame))); + return make_fixnum (FRAME_SCROLL_BAR_AREA_WIDTH (decode_any_frame (frame))); } DEFUN ("frame-scroll-bar-height", Fscroll_bar_height, Sscroll_bar_height, 0, 1, 0, doc: /* Return scroll bar height of FRAME in pixels. */) (Lisp_Object frame) { - return make_number (FRAME_SCROLL_BAR_AREA_HEIGHT (decode_any_frame (frame))); + return make_fixnum (FRAME_SCROLL_BAR_AREA_HEIGHT (decode_any_frame (frame))); } DEFUN ("frame-fringe-width", Ffringe_width, Sfringe_width, 0, 1, 0, doc: /* Return fringe width of FRAME in pixels. */) (Lisp_Object frame) { - return make_number (FRAME_TOTAL_FRINGE_WIDTH (decode_any_frame (frame))); + return make_fixnum (FRAME_TOTAL_FRINGE_WIDTH (decode_any_frame (frame))); +} + +DEFUN ("frame-child-frame-border-width", Fframe_child_frame_border_width, Sframe_child_frame_border_width, 0, 1, 0, + doc: /* Return width of FRAME's child-frame border in pixels. + If FRAME's `child-frame-border-width' parameter is nil, return FRAME's + internal border width instead. */) + (Lisp_Object frame) +{ + int width = FRAME_CHILD_FRAME_BORDER_WIDTH (decode_any_frame (frame)); + + if (width < 0) + return make_fixnum (FRAME_INTERNAL_BORDER_WIDTH (decode_any_frame (frame))); + else + return make_fixnum (FRAME_CHILD_FRAME_BORDER_WIDTH (decode_any_frame (frame))); } DEFUN ("frame-internal-border-width", Fframe_internal_border_width, Sframe_internal_border_width, 0, 1, 0, doc: /* Return width of FRAME's internal border in pixels. */) (Lisp_Object frame) { - return make_number (FRAME_INTERNAL_BORDER_WIDTH (decode_any_frame (frame))); + return make_fixnum (FRAME_INTERNAL_BORDER_WIDTH (decode_any_frame (frame))); } DEFUN ("frame-right-divider-width", Fright_divider_width, Sright_divider_width, 0, 1, 0, doc: /* Return width (in pixels) of vertical window dividers on FRAME. */) (Lisp_Object frame) { - return make_number (FRAME_RIGHT_DIVIDER_WIDTH (decode_any_frame (frame))); + return make_fixnum (FRAME_RIGHT_DIVIDER_WIDTH (decode_any_frame (frame))); } DEFUN ("frame-bottom-divider-width", Fbottom_divider_width, Sbottom_divider_width, 0, 1, 0, doc: /* Return width (in pixels) of horizontal window dividers on FRAME. */) (Lisp_Object frame) { - return make_number (FRAME_BOTTOM_DIVIDER_WIDTH (decode_any_frame (frame))); + return make_fixnum (FRAME_BOTTOM_DIVIDER_WIDTH (decode_any_frame (frame))); +} + +static int +check_frame_pixels (Lisp_Object size, Lisp_Object pixelwise, int item_size) +{ + intmax_t sz; + int pixel_size; /* size * item_size */ + + CHECK_INTEGER (size); + if (!NILP (pixelwise)) + item_size = 1; + + if (!integer_to_intmax (size, &sz) + || INT_MULTIPLY_WRAPV (sz, item_size, &pixel_size)) + args_out_of_range_3 (size, make_int (INT_MIN / item_size), + make_int (INT_MAX / item_size)); + + return pixel_size; } -DEFUN ("set-frame-height", Fset_frame_height, Sset_frame_height, 2, 4, 0, +DEFUN ("set-frame-height", Fset_frame_height, Sset_frame_height, 2, 4, + "(set-frame-property--interactive \"Frame height: \" (frame-height))", doc: /* Set text height of frame FRAME to HEIGHT lines. Optional third arg PRETEND non-nil means that redisplay should use HEIGHT lines but that the idea of the actual height of the frame should @@ -3379,23 +3686,27 @@ not be changed. Optional fourth argument PIXELWISE non-nil means that FRAME should be HEIGHT pixels high. Note: When `frame-resize-pixelwise' is nil, some window managers may refuse to honor a HEIGHT that is not an integer -multiple of the default frame font height. */) +multiple of the default frame font height. + +When called interactively, HEIGHT is the numeric prefix and the +currently selected frame will be set to this height. + +If FRAME is nil, it defaults to the selected frame. */) (Lisp_Object frame, Lisp_Object height, Lisp_Object pretend, Lisp_Object pixelwise) { struct frame *f = decode_live_frame (frame); - int pixel_height; + int text_height + = check_frame_pixels (height, pixelwise, FRAME_LINE_HEIGHT (f)); - CHECK_TYPE_RANGED_INTEGER (int, height); - - pixel_height = (!NILP (pixelwise) - ? XINT (height) - : XINT (height) * FRAME_LINE_HEIGHT (f)); - adjust_frame_size (f, -1, pixel_height, 1, !NILP (pretend), Qheight); + /* With INHIBIT 1 pass correct text width to adjust_frame_size. */ + adjust_frame_size + (f, FRAME_TEXT_WIDTH (f), text_height, 1, !NILP (pretend), Qheight); return Qnil; } -DEFUN ("set-frame-width", Fset_frame_width, Sset_frame_width, 2, 4, 0, +DEFUN ("set-frame-width", Fset_frame_width, Sset_frame_width, 2, 4, + "(set-frame-property--interactive \"Frame width: \" (frame-width))", doc: /* Set text width of frame FRAME to WIDTH columns. Optional third arg PRETEND non-nil means that redisplay should use WIDTH columns but that the idea of the actual width of the frame should not @@ -3404,18 +3715,21 @@ be changed. Optional fourth argument PIXELWISE non-nil means that FRAME should be WIDTH pixels wide. Note: When `frame-resize-pixelwise' is nil, some window managers may refuse to honor a WIDTH that is not an integer -multiple of the default frame font width. */) +multiple of the default frame font width. + +When called interactively, WIDTH is the numeric prefix and the +currently selected frame will be set to this width. + +If FRAME is nil, it defaults to the selected frame. */) (Lisp_Object frame, Lisp_Object width, Lisp_Object pretend, Lisp_Object pixelwise) { struct frame *f = decode_live_frame (frame); - int pixel_width; - - CHECK_TYPE_RANGED_INTEGER (int, width); + int text_width + = check_frame_pixels (width, pixelwise, FRAME_COLUMN_WIDTH (f)); - pixel_width = (!NILP (pixelwise) - ? XINT (width) - : XINT (width) * FRAME_COLUMN_WIDTH (f)); - adjust_frame_size (f, pixel_width, -1, 1, !NILP (pretend), Qwidth); + /* With INHIBIT 1 pass correct text height to adjust_frame_size. */ + adjust_frame_size + (f, text_width, FRAME_TEXT_HEIGHT (f), 1, !NILP (pretend), Qwidth); return Qnil; } @@ -3426,22 +3740,19 @@ Optional argument PIXELWISE non-nil means to measure in pixels. Note: When `frame-resize-pixelwise' is nil, some window managers may refuse to honor a WIDTH that is not an integer multiple of the default frame font width or a HEIGHT that is not an integer multiple of the default frame -font height. */) +font height. + +If FRAME is nil, it defaults to the selected frame. */) (Lisp_Object frame, Lisp_Object width, Lisp_Object height, Lisp_Object pixelwise) { struct frame *f = decode_live_frame (frame); - int pixel_width, pixel_height; - - CHECK_TYPE_RANGED_INTEGER (int, width); - CHECK_TYPE_RANGED_INTEGER (int, height); + int text_width + = check_frame_pixels (width, pixelwise, FRAME_COLUMN_WIDTH (f)); + int text_height + = check_frame_pixels (height, pixelwise, FRAME_LINE_HEIGHT (f)); - pixel_width = (!NILP (pixelwise) - ? XINT (width) - : XINT (width) * FRAME_COLUMN_WIDTH (f)); - pixel_height = (!NILP (pixelwise) - ? XINT (height) - : XINT (height) * FRAME_LINE_HEIGHT (f)); - adjust_frame_size (f, pixel_width, pixel_height, 1, 0, Qsize); + /* PRETEND is always false here. */ + adjust_frame_size (f, text_width, text_height, 1, false, Qsize); return Qnil; } @@ -3452,12 +3763,16 @@ DEFUN ("frame-position", Fframe_position, FRAME must be a live frame and defaults to the selected one. The return value is a cons (x, y) of the coordinates of the top left corner of FRAME's outer frame, in pixels relative to an origin (0, 0) of FRAME's -display. */) +display. + +Note that the values returned are not guaranteed to be accurate: The +values depend on the underlying window system, and some systems add a +constant offset to the values. */) (Lisp_Object frame) { register struct frame *f = decode_live_frame (frame); - return Fcons (make_number (f->left_pos), make_number (f->top_pos)); + return Fcons (make_fixnum (f->left_pos), make_fixnum (f->top_pos)); } DEFUN ("set-frame-position", Fset_frame_position, @@ -3472,31 +3787,79 @@ bottom edge of FRAME's display. */) (Lisp_Object frame, Lisp_Object x, Lisp_Object y) { struct frame *f = decode_live_frame (frame); + int xval = check_integer_range (x, INT_MIN, INT_MAX); + int yval = check_integer_range (y, INT_MIN, INT_MAX); - CHECK_TYPE_RANGED_INTEGER (int, x); - CHECK_TYPE_RANGED_INTEGER (int, y); - - /* I think this should be done with a hook. */ if (FRAME_WINDOW_P (f)) { #ifdef HAVE_WINDOW_SYSTEM - x_set_offset (f, XINT (x), XINT (y), 1); + if (FRAME_TERMINAL (f)->set_frame_offset_hook) + FRAME_TERMINAL (f)->set_frame_offset_hook (f, xval, yval, 1); +#else + (void) xval; + (void) yval; #endif } return Qt; } + +DEFUN ("frame-window-state-change", Fframe_window_state_change, + Sframe_window_state_change, 0, 1, 0, + doc: /* Return t if FRAME's window state change flag is set, nil otherwise. +FRAME must be a live frame and defaults to the selected one. + +If FRAME's window state change flag is set, the default values of +`window-state-change-functions' and `window-state-change-hook' will be +run during next redisplay, regardless of whether a window state change +actually occurred on FRAME or not. After that, the value of this flag +is reset. */) + (Lisp_Object frame) +{ + return FRAME_WINDOW_STATE_CHANGE (decode_live_frame (frame)) ? Qt : Qnil; +} + +DEFUN ("set-frame-window-state-change", Fset_frame_window_state_change, + Sset_frame_window_state_change, 0, 2, 0, + doc: /* Set FRAME's window state change flag according to ARG. +Set FRAME's window state change flag if ARG is non-nil, reset it +otherwise. + +If FRAME's window state change flag is set, the default values of +`window-state-change-functions' and `window-state-change-hook' will be +run during next redisplay, regardless of whether a window state change +actually occurred on FRAME or not. After that, the value of FRAME's +window state change flag is reset. */) + (Lisp_Object frame, Lisp_Object arg) +{ + struct frame *f = decode_live_frame (frame); + + return (FRAME_WINDOW_STATE_CHANGE (f) = !NILP (arg)) ? Qt : Qnil; +} + +DEFUN ("frame-scale-factor", Fframe_scale_factor, Sframe_scale_factor, + 0, 1, 0, + doc: /* Return FRAMEs scale factor. +If FRAME is omitted or nil, the selected frame is used. +The scale factor is the amount by which a logical pixel size must be +multiplied to find the real number of pixels. */) + (Lisp_Object frame) +{ + struct frame *f = decode_live_frame (frame); + + return (make_float (f ? FRAME_SCALE_FACTOR (f) : 1)); +} /*********************************************************************** Frame Parameters ***********************************************************************/ -/* Connect the frame-parameter names for X frames - to the ways of passing the parameter values to the window system. +/* Connect the frame-parameter names for frames to the ways of passing + the parameter values to the window system. - The name of a parameter, as a Lisp symbol, - has an `x-frame-parameter' property which is an integer in Lisp - that is an index in this table. */ + The name of a parameter, as a Lisp symbol, has a + `frame-parameter-pos' property which is an integer in Lisp that is + an index in this table. */ struct frame_parm_table { const char *name; @@ -3516,6 +3879,7 @@ static const struct frame_parm_table frame_parms[] = {"foreground-color", -1}, {"icon-name", SYMBOL_INDEX (Qicon_name)}, {"icon-type", SYMBOL_INDEX (Qicon_type)}, + {"child-frame-border-width", SYMBOL_INDEX (Qchild_frame_border_width)}, {"internal-border-width", SYMBOL_INDEX (Qinternal_border_width)}, {"right-divider-width", SYMBOL_INDEX (Qright_divider_width)}, {"bottom-divider-width", SYMBOL_INDEX (Qbottom_divider_width)}, @@ -3529,6 +3893,7 @@ static const struct frame_parm_table frame_parms[] = {"vertical-scroll-bars", SYMBOL_INDEX (Qvertical_scroll_bars)}, {"horizontal-scroll-bars", SYMBOL_INDEX (Qhorizontal_scroll_bars)}, {"visibility", SYMBOL_INDEX (Qvisibility)}, + {"tab-bar-lines", SYMBOL_INDEX (Qtab_bar_lines)}, {"tool-bar-lines", SYMBOL_INDEX (Qtool_bar_lines)}, {"scroll-bar-foreground", SYMBOL_INDEX (Qscroll_bar_foreground)}, {"scroll-bar-background", SYMBOL_INDEX (Qscroll_bar_background)}, @@ -3551,6 +3916,11 @@ static const struct frame_parm_table frame_parms[] = {"z-group", SYMBOL_INDEX (Qz_group)}, {"override-redirect", SYMBOL_INDEX (Qoverride_redirect)}, {"no-special-glyphs", SYMBOL_INDEX (Qno_special_glyphs)}, + {"alpha-background", SYMBOL_INDEX (Qalpha_background)}, + {"use-frame-synchronization", SYMBOL_INDEX (Quse_frame_synchronization)}, +#ifdef HAVE_X_WINDOWS + {"shaded", SYMBOL_INDEX (Qshaded)}, +#endif #ifdef NS_IMPL_COCOA {"ns-appearance", SYMBOL_INDEX (Qns_appearance)}, {"ns-transparent-titlebar", SYMBOL_INDEX (Qns_transparent_titlebar)}, @@ -3630,7 +4000,7 @@ frame_float (struct frame *f, Lisp_Object val, enum frame_float_type what, Lisp_Object frame; XSETFRAME (frame, f); - monitor_attributes = Fcar (call1 (Qdisplay_monitor_attributes_list, frame)); + monitor_attributes = call1 (Qframe_monitor_attributes, frame); if (NILP (monitor_attributes)) { /* No monitor attributes available. */ @@ -3649,10 +4019,10 @@ frame_float (struct frame *f, Lisp_Object val, enum frame_float_type what, } /* Workarea available. */ - parent_left = XINT (Fnth (make_number (0), workarea)); - parent_top = XINT (Fnth (make_number (1), workarea)); - parent_width = XINT (Fnth (make_number (2), workarea)); - parent_height = XINT (Fnth (make_number (3), workarea)); + parent_left = XFIXNUM (Fnth (make_fixnum (0), workarea)); + parent_top = XFIXNUM (Fnth (make_fixnum (1), workarea)); + parent_width = XFIXNUM (Fnth (make_fixnum (2), workarea)); + parent_height = XFIXNUM (Fnth (make_fixnum (3), workarea)); *parent_done = 1; } } @@ -3680,12 +4050,12 @@ frame_float (struct frame *f, Lisp_Object val, enum frame_float_type what, if (!NILP (outer_edges)) { outer_minus_text_width - = (XINT (Fnth (make_number (2), outer_edges)) - - XINT (Fnth (make_number (0), outer_edges)) + = (XFIXNUM (Fnth (make_fixnum (2), outer_edges)) + - XFIXNUM (Fnth (make_fixnum (0), outer_edges)) - FRAME_TEXT_WIDTH (f)); outer_minus_text_height - = (XINT (Fnth (make_number (3), outer_edges)) - - XINT (Fnth (make_number (1), outer_edges)) + = (XFIXNUM (Fnth (make_fixnum (3), outer_edges)) + - XFIXNUM (Fnth (make_fixnum (1), outer_edges)) - FRAME_TEXT_HEIGHT (f)); } else @@ -3743,20 +4113,18 @@ frame_float (struct frame *f, Lisp_Object val, enum frame_float_type what, /* Change the parameters of frame F as specified by ALIST. If a parameter is not specially recognized, do nothing special; - otherwise call the `x_set_...' function for that parameter. + otherwise call the `gui_set_...' function for that parameter. Except for certain geometry properties, always call store_frame_param to store the new value in the parameter alist. */ void -x_set_frame_parameters (struct frame *f, Lisp_Object alist) +gui_set_frame_parameters (struct frame *f, Lisp_Object alist) { Lisp_Object tail, frame; - - /* If both of these parameters are present, it's more efficient to - set them both at once. So we wait until we've looked at the - entire list before we set them. */ - int width = -1, height = -1; /* -1 denotes they were not changed. */ + /* Neither of these values should be used. */ + int width = -1, height = -1; + bool width_change = false, height_change = false; /* Same here. */ Lisp_Object left, top; @@ -3765,7 +4133,7 @@ x_set_frame_parameters (struct frame *f, Lisp_Object alist) Lisp_Object icon_left, icon_top; /* And with this. */ - Lisp_Object fullscreen; + Lisp_Object fullscreen UNINIT; bool fullscreen_change = false; /* Record in these vectors all the parms specified. */ @@ -3834,25 +4202,33 @@ x_set_frame_parameters (struct frame *f, Lisp_Object alist) if (EQ (prop, Qwidth)) { - if (RANGED_INTEGERP (0, val, INT_MAX)) - width = XFASTINT (val) * FRAME_COLUMN_WIDTH (f) ; + width_change = true; + + if (RANGED_FIXNUMP (0, val, INT_MAX)) + width = XFIXNAT (val) * FRAME_COLUMN_WIDTH (f) ; else if (CONSP (val) && EQ (XCAR (val), Qtext_pixels) - && RANGED_INTEGERP (0, XCDR (val), INT_MAX)) - width = XFASTINT (XCDR (val)); + && RANGED_FIXNUMP (0, XCDR (val), INT_MAX)) + width = XFIXNAT (XCDR (val)); else if (FLOATP (val)) width = frame_float (f, val, FRAME_FLOAT_WIDTH, &parent_done, &outer_done, -1); + else + width_change = false; } else if (EQ (prop, Qheight)) { - if (RANGED_INTEGERP (0, val, INT_MAX)) - height = XFASTINT (val) * FRAME_LINE_HEIGHT (f); + height_change = true; + + if (RANGED_FIXNUMP (0, val, INT_MAX)) + height = XFIXNAT (val) * FRAME_LINE_HEIGHT (f); else if (CONSP (val) && EQ (XCAR (val), Qtext_pixels) - && RANGED_INTEGERP (0, XCDR (val), INT_MAX)) - height = XFASTINT (XCDR (val)); + && RANGED_FIXNUMP (0, XCDR (val), INT_MAX)) + height = XFIXNAT (XCDR (val)); else if (FLOATP (val)) height = frame_float (f, val, FRAME_FLOAT_HEIGHT, &parent_done, &outer_done, -1); + else + height_change = false; } else if (EQ (prop, Qtop)) top = val; @@ -3876,33 +4252,33 @@ x_set_frame_parameters (struct frame *f, Lisp_Object alist) store_frame_param (f, prop, val); param_index = Fget (prop, Qx_frame_parameter); - if (NATNUMP (param_index) - && XFASTINT (param_index) < ARRAYELTS (frame_parms) - && FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)]) - (*(FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])) (f, val, old_value); + if (FIXNATP (param_index) + && XFIXNAT (param_index) < ARRAYELTS (frame_parms) + && FRAME_RIF (f)->frame_parm_handlers[XFIXNUM (param_index)]) + (*(FRAME_RIF (f)->frame_parm_handlers[XFIXNUM (param_index)])) (f, val, old_value); } } /* Don't die if just one of these was set. */ - if (EQ (left, Qunbound)) + if (BASE_EQ (left, Qunbound)) { left_no_change = 1; if (f->left_pos < 0) - left = list2 (Qplus, make_number (f->left_pos)); + left = list2 (Qplus, make_fixnum (f->left_pos)); else XSETINT (left, f->left_pos); } - if (EQ (top, Qunbound)) + if (BASE_EQ (top, Qunbound)) { top_no_change = 1; if (f->top_pos < 0) - top = list2 (Qplus, make_number (f->top_pos)); + top = list2 (Qplus, make_fixnum (f->top_pos)); else XSETINT (top, f->top_pos); } /* If one of the icon positions was not set, preserve or default it. */ - if (! TYPE_RANGED_INTEGERP (int, icon_left)) + if (! TYPE_RANGED_FIXNUMP (int, icon_left)) { #ifdef HAVE_X_WINDOWS icon_left_no_change = 1; @@ -3911,7 +4287,7 @@ x_set_frame_parameters (struct frame *f, Lisp_Object alist) if (NILP (icon_left)) XSETINT (icon_left, 0); } - if (! TYPE_RANGED_INTEGERP (int, icon_top)) + if (! TYPE_RANGED_FIXNUMP (int, icon_top)) { #ifdef HAVE_X_WINDOWS icon_top_no_change = 1; @@ -3921,28 +4297,33 @@ x_set_frame_parameters (struct frame *f, Lisp_Object alist) XSETINT (icon_top, 0); } - /* Don't set these parameters unless they've been explicitly - specified. The window might be mapped or resized while we're in - this function, and we don't want to override that unless the lisp - code has asked for it. - - Don't set these parameters unless they actually differ from the - window's current parameters; the window may not actually exist - yet. */ - if ((width != -1 && width != FRAME_TEXT_WIDTH (f)) - || (height != -1 && height != FRAME_TEXT_HEIGHT (f))) - /* We could consider checking f->after_make_frame here, but I - don't have the faintest idea why the following is needed at - all. With the old setting it can get a Heisenbug when - EmacsFrameResize intermittently provokes a delayed - change_frame_size in the middle of adjust_frame_size. */ - /** || (f->can_x_set_window_size && (f->new_height || f->new_width))) **/ - adjust_frame_size (f, width, height, 1, 0, Qx_set_frame_parameters); + if (width_change || height_change) + { + Lisp_Object parameter; + + if (width_change) + { + if (height_change) + parameter = Qsize; + else + { + height = FRAME_TEXT_HEIGHT (f); + parameter = Qwidth; + } + } + else + { + width = FRAME_TEXT_WIDTH (f); + parameter = Qheight; + } + + adjust_frame_size (f, width, height, 1, 0, parameter); + } if ((!NILP (left) || !NILP (top)) && ! (left_no_change && top_no_change) - && ! (NUMBERP (left) && XINT (left) == f->left_pos - && NUMBERP (top) && XINT (top) == f->top_pos)) + && ! (FIXNUMP (left) && XFIXNUM (left) == f->left_pos + && FIXNUMP (top) && XFIXNUM (top) == f->top_pos)) { int leftpos = 0; int toppos = 0; @@ -3951,46 +4332,46 @@ x_set_frame_parameters (struct frame *f, Lisp_Object alist) f->size_hint_flags &= ~ (XNegative | YNegative); if (EQ (left, Qminus)) f->size_hint_flags |= XNegative; - else if (TYPE_RANGED_INTEGERP (int, left)) + else if (TYPE_RANGED_FIXNUMP (int, left)) { - leftpos = XINT (left); + leftpos = XFIXNUM (left); if (leftpos < 0) f->size_hint_flags |= XNegative; } else if (CONSP (left) && EQ (XCAR (left), Qminus) && CONSP (XCDR (left)) - && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (left)), INT_MAX)) + && RANGED_FIXNUMP (-INT_MAX, XCAR (XCDR (left)), INT_MAX)) { - leftpos = - XINT (XCAR (XCDR (left))); + leftpos = - XFIXNUM (XCAR (XCDR (left))); f->size_hint_flags |= XNegative; } else if (CONSP (left) && EQ (XCAR (left), Qplus) && CONSP (XCDR (left)) - && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (left)))) - leftpos = XINT (XCAR (XCDR (left))); + && TYPE_RANGED_FIXNUMP (int, XCAR (XCDR (left)))) + leftpos = XFIXNUM (XCAR (XCDR (left))); else if (FLOATP (left)) leftpos = frame_float (f, left, FRAME_FLOAT_LEFT, &parent_done, &outer_done, 0); if (EQ (top, Qminus)) f->size_hint_flags |= YNegative; - else if (TYPE_RANGED_INTEGERP (int, top)) + else if (TYPE_RANGED_FIXNUMP (int, top)) { - toppos = XINT (top); + toppos = XFIXNUM (top); if (toppos < 0) f->size_hint_flags |= YNegative; } else if (CONSP (top) && EQ (XCAR (top), Qminus) && CONSP (XCDR (top)) - && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (top)), INT_MAX)) + && RANGED_FIXNUMP (-INT_MAX, XCAR (XCDR (top)), INT_MAX)) { - toppos = - XINT (XCAR (XCDR (top))); + toppos = - XFIXNUM (XCAR (XCDR (top))); f->size_hint_flags |= YNegative; } else if (CONSP (top) && EQ (XCAR (top), Qplus) && CONSP (XCDR (top)) - && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (top)))) - toppos = XINT (XCAR (XCDR (top))); + && TYPE_RANGED_FIXNUMP (int, XCAR (XCDR (top)))) + toppos = XFIXNUM (XCAR (XCDR (top))); else if (FLOATP (top)) toppos = frame_float (f, top, FRAME_FLOAT_TOP, &parent_done, &outer_done, 0); @@ -4002,43 +4383,41 @@ x_set_frame_parameters (struct frame *f, Lisp_Object alist) f->win_gravity = NorthWestGravity; /* Actually set that position, and convert to absolute. */ - x_set_offset (f, leftpos, toppos, -1); + if (FRAME_TERMINAL (f)->set_frame_offset_hook) + FRAME_TERMINAL (f)->set_frame_offset_hook (f, leftpos, toppos, -1); } if (fullscreen_change) { Lisp_Object old_value = get_frame_param (f, Qfullscreen); - frame_size_history_add - (f, Qx_set_fullscreen, 0, 0, list2 (old_value, fullscreen)); - store_frame_param (f, Qfullscreen, fullscreen); if (!EQ (fullscreen, old_value)) - x_set_fullscreen (f, fullscreen, old_value); + gui_set_fullscreen (f, fullscreen, old_value); } #ifdef HAVE_X_WINDOWS if ((!NILP (icon_left) || !NILP (icon_top)) && ! (icon_left_no_change && icon_top_no_change)) - x_wm_set_icon_position (f, XINT (icon_left), XINT (icon_top)); + x_wm_set_icon_position (f, XFIXNUM (icon_left), XFIXNUM (icon_top)); #endif /* HAVE_X_WINDOWS */ SAFE_FREE (); } -/* Insert a description of internally-recorded parameters of frame X +/* Insert a description of internally-recorded parameters of frame F into the parameter alist *ALISTPTR that is to be given to the user. Only parameters that are specific to the X window system and whose values are not correctly recorded in the frame's param_alist need to be considered here. */ void -x_report_frame_params (struct frame *f, Lisp_Object *alistptr) +gui_report_frame_params (struct frame *f, Lisp_Object *alistptr) { Lisp_Object tem; - uprintmax_t w; + uintmax_t w; char buf[INT_BUFSIZE_BOUND (w)]; /* Represent negative positions (off the top or left screen edge) @@ -4056,41 +4435,41 @@ x_report_frame_params (struct frame *f, Lisp_Object *alistptr) store_in_alist (alistptr, Qtop, list2 (Qplus, tem)); store_in_alist (alistptr, Qborder_width, - make_number (f->border_width)); + make_fixnum (f->border_width)); + store_in_alist (alistptr, Qchild_frame_border_width, + FRAME_CHILD_FRAME_BORDER_WIDTH (f) >= 0 + ? make_fixnum (FRAME_CHILD_FRAME_BORDER_WIDTH (f)) + : Qnil); store_in_alist (alistptr, Qinternal_border_width, - make_number (FRAME_INTERNAL_BORDER_WIDTH (f))); + make_fixnum (FRAME_INTERNAL_BORDER_WIDTH (f))); store_in_alist (alistptr, Qright_divider_width, - make_number (FRAME_RIGHT_DIVIDER_WIDTH (f))); + make_fixnum (FRAME_RIGHT_DIVIDER_WIDTH (f))); store_in_alist (alistptr, Qbottom_divider_width, - make_number (FRAME_BOTTOM_DIVIDER_WIDTH (f))); + make_fixnum (FRAME_BOTTOM_DIVIDER_WIDTH (f))); store_in_alist (alistptr, Qleft_fringe, - make_number (FRAME_LEFT_FRINGE_WIDTH (f))); + make_fixnum (FRAME_LEFT_FRINGE_WIDTH (f))); store_in_alist (alistptr, Qright_fringe, - make_number (FRAME_RIGHT_FRINGE_WIDTH (f))); + make_fixnum (FRAME_RIGHT_FRINGE_WIDTH (f))); store_in_alist (alistptr, Qscroll_bar_width, - (! FRAME_HAS_VERTICAL_SCROLL_BARS (f) - ? make_number (0) - : FRAME_CONFIG_SCROLL_BAR_WIDTH (f) > 0 - ? make_number (FRAME_CONFIG_SCROLL_BAR_WIDTH (f)) + (FRAME_CONFIG_SCROLL_BAR_WIDTH (f) > 0 + ? make_fixnum (FRAME_CONFIG_SCROLL_BAR_WIDTH (f)) /* nil means "use default width" for non-toolkit scroll bar. ruler-mode.el depends on this. */ : Qnil)); store_in_alist (alistptr, Qscroll_bar_height, - (! FRAME_HAS_HORIZONTAL_SCROLL_BARS (f) - ? make_number (0) - : FRAME_CONFIG_SCROLL_BAR_HEIGHT (f) > 0 - ? make_number (FRAME_CONFIG_SCROLL_BAR_HEIGHT (f)) + (FRAME_CONFIG_SCROLL_BAR_HEIGHT (f) > 0 + ? make_fixnum (FRAME_CONFIG_SCROLL_BAR_HEIGHT (f)) /* nil means "use default height" for non-toolkit scroll bar. */ : Qnil)); - /* FRAME_X_WINDOW is not guaranteed to return an integer. E.g., on - MS-Windows it returns a value whose type is HANDLE, which is - actually a pointer. Explicit casting avoids compiler + /* FRAME_NATIVE_WINDOW is not guaranteed to return an integer. + E.g., on MS-Windows it returns a value whose type is HANDLE, + which is actually a pointer. Explicit casting avoids compiler warnings. */ - w = (uintptr_t) FRAME_X_WINDOW (f); + w = (uintptr_t) FRAME_NATIVE_WINDOW (f); store_in_alist (alistptr, Qwindow_id, - make_formatted_string (buf, "%"pMu, w)); + make_formatted_string (buf, "%"PRIuMAX, w)); #ifdef HAVE_X_WINDOWS #ifdef USE_X_TOOLKIT /* Tooltip frame may not have this widget. */ @@ -4098,7 +4477,7 @@ x_report_frame_params (struct frame *f, Lisp_Object *alistptr) #endif w = (uintptr_t) FRAME_OUTER_WINDOW (f); store_in_alist (alistptr, Qouter_window_id, - make_formatted_string (buf, "%"pMu, w)); + make_formatted_string (buf, "%"PRIuMAX, w)); #endif store_in_alist (alistptr, Qicon_name, f->icon_name); store_in_alist (alistptr, Qvisibility, @@ -4107,10 +4486,10 @@ x_report_frame_params (struct frame *f, Lisp_Object *alistptr) store_in_alist (alistptr, Qdisplay, XCAR (FRAME_DISPLAY_INFO (f)->name_list_element)); - if (FRAME_X_OUTPUT (f)->parent_desc == FRAME_DISPLAY_INFO (f)->root_window) + if (FRAME_OUTPUT_DATA (f)->parent_desc == FRAME_DISPLAY_INFO (f)->root_window) tem = Qnil; else - tem = make_natnum ((uintptr_t) FRAME_X_OUTPUT (f)->parent_desc); + tem = make_fixed_natnum ((uintptr_t) FRAME_OUTPUT_DATA (f)->parent_desc); store_in_alist (alistptr, Qexplicit_name, (f->explicit_name ? Qt : Qnil)); store_in_alist (alistptr, Qparent_id, tem); store_in_alist (alistptr, Qtool_bar_position, FRAME_TOOL_BAR_POSITION (f)); @@ -4121,7 +4500,7 @@ x_report_frame_params (struct frame *f, Lisp_Object *alistptr) the previous value of that parameter, NEW_VALUE is the new value. */ void -x_set_fullscreen (struct frame *f, Lisp_Object new_value, Lisp_Object old_value) +gui_set_fullscreen (struct frame *f, Lisp_Object new_value, Lisp_Object old_value) { if (NILP (new_value)) f->want_fullscreen = FULLSCREEN_NONE; @@ -4143,12 +4522,12 @@ x_set_fullscreen (struct frame *f, Lisp_Object new_value, Lisp_Object old_value) the previous value of that parameter, NEW_VALUE is the new value. */ void -x_set_line_spacing (struct frame *f, Lisp_Object new_value, Lisp_Object old_value) +gui_set_line_spacing (struct frame *f, Lisp_Object new_value, Lisp_Object old_value) { if (NILP (new_value)) f->extra_line_spacing = 0; - else if (RANGED_INTEGERP (0, new_value, INT_MAX)) - f->extra_line_spacing = XFASTINT (new_value); + else if (RANGED_FIXNUMP (0, new_value, INT_MAX)) + f->extra_line_spacing = XFIXNAT (new_value); else if (FLOATP (new_value)) { int new_spacing = XFLOAT_DATA (new_value) * FRAME_LINE_HEIGHT (f) + 0.5; @@ -4169,7 +4548,7 @@ x_set_line_spacing (struct frame *f, Lisp_Object new_value, Lisp_Object old_valu the previous value of that parameter, NEW_VALUE is the new value. */ void -x_set_screen_gamma (struct frame *f, Lisp_Object new_value, Lisp_Object old_value) +gui_set_screen_gamma (struct frame *f, Lisp_Object new_value, Lisp_Object old_value) { Lisp_Object bgcolor; @@ -4186,10 +4565,10 @@ x_set_screen_gamma (struct frame *f, Lisp_Object new_value, Lisp_Object old_valu if (CONSP (bgcolor) && (bgcolor = XCDR (bgcolor), STRINGP (bgcolor))) { Lisp_Object parm_index = Fget (Qbackground_color, Qx_frame_parameter); - if (NATNUMP (parm_index) - && XFASTINT (parm_index) < ARRAYELTS (frame_parms) - && FRAME_RIF (f)->frame_parm_handlers[XFASTINT (parm_index)]) - (*FRAME_RIF (f)->frame_parm_handlers[XFASTINT (parm_index)]) + if (FIXNATP (parm_index) + && XFIXNAT (parm_index) < ARRAYELTS (frame_parms) + && FRAME_RIF (f)->frame_parm_handlers[XFIXNAT (parm_index)]) + (*FRAME_RIF (f)->frame_parm_handlers[XFIXNAT (parm_index)]) (f, bgcolor, Qnil); } @@ -4199,7 +4578,7 @@ x_set_screen_gamma (struct frame *f, Lisp_Object new_value, Lisp_Object old_valu void -x_set_font (struct frame *f, Lisp_Object arg, Lisp_Object oldval) +gui_set_font (struct frame *f, Lisp_Object arg, Lisp_Object oldval) { Lisp_Object font_object; int fontset = -1; @@ -4269,8 +4648,8 @@ x_set_font (struct frame *f, Lisp_Object arg, Lisp_Object oldval) /* SPEC might be nil because ASCII_FONT's name doesn't parse according to stupid XLFD rules, which, for example, disallow font names that include a dash followed by a - number. So in those cases we simply request x_new_font - below to generate a new fontset. */ + number. So in those cases we simply call + set_new_font_hook below to generate a new fontset. */ if (NILP (spec) || ! font_match_p (spec, font_object)) fontset = -1; } @@ -4281,11 +4660,14 @@ x_set_font (struct frame *f, Lisp_Object arg, Lisp_Object oldval) if (! NILP (Fequal (font_object, oldval))) return; - x_new_font (f, font_object, fontset); + if (FRAME_TERMINAL (f)->set_new_font_hook) + FRAME_TERMINAL (f)->set_new_font_hook (f, font_object, fontset); store_frame_param (f, Qfont, arg); #ifdef HAVE_X_WINDOWS store_frame_param (f, Qfont_parameter, font_param); #endif + /* Recalculate tabbar height. */ + f->n_tab_bar_rows = 0; /* Recalculate toolbar height. */ f->n_tool_bar_rows = 0; @@ -4313,7 +4695,7 @@ x_set_font (struct frame *f, Lisp_Object arg, Lisp_Object oldval) void -x_set_font_backend (struct frame *f, Lisp_Object new_value, Lisp_Object old_value) +gui_set_font_backend (struct frame *f, Lisp_Object new_value, Lisp_Object old_value) { if (! NILP (new_value) && !CONSP (new_value)) @@ -4344,7 +4726,11 @@ x_set_font_backend (struct frame *f, Lisp_Object new_value, Lisp_Object old_valu return; if (FRAME_FONT (f)) - free_all_realized_faces (Qnil); + { + Lisp_Object frame; + XSETFRAME (frame, f); + free_all_realized_faces (frame); + } new_value = font_update_drivers (f, NILP (new_value) ? Qt : new_value); if (NILP (new_value)) @@ -4358,24 +4744,22 @@ x_set_font_backend (struct frame *f, Lisp_Object new_value, Lisp_Object old_valu if (FRAME_FONT (f)) { - Lisp_Object frame; - - XSETFRAME (frame, f); - x_set_font (f, Fframe_parameter (frame, Qfont), Qnil); + /* Reconsider default font after backend(s) change (Bug#23386). */ + FRAME_RIF(f)->default_font_parameter (f, Qnil); face_change = true; windows_or_buffers_changed = 18; } } void -x_set_left_fringe (struct frame *f, Lisp_Object new_value, Lisp_Object old_value) +gui_set_left_fringe (struct frame *f, Lisp_Object new_value, Lisp_Object old_value) { int unit = FRAME_COLUMN_WIDTH (f); int old_width = FRAME_LEFT_FRINGE_WIDTH (f); int new_width; - new_width = (RANGED_INTEGERP (-INT_MAX, new_value, INT_MAX) - ? eabs (XINT (new_value)) : 8); + new_width = (RANGED_FIXNUMP (-INT_MAX, new_value, INT_MAX) + ? eabs (XFIXNUM (new_value)) : 8); if (new_width != old_width) { @@ -4383,7 +4767,7 @@ x_set_left_fringe (struct frame *f, Lisp_Object new_value, Lisp_Object old_value f->fringe_cols /* Round up. */ = (new_width + FRAME_RIGHT_FRINGE_WIDTH (f) + unit - 1) / unit; - if (FRAME_X_WINDOW (f) != 0) + if (FRAME_NATIVE_WINDOW (f) != 0) adjust_frame_size (f, -1, -1, 3, 0, Qleft_fringe); SET_FRAME_GARBAGED (f); @@ -4392,14 +4776,14 @@ x_set_left_fringe (struct frame *f, Lisp_Object new_value, Lisp_Object old_value void -x_set_right_fringe (struct frame *f, Lisp_Object new_value, Lisp_Object old_value) +gui_set_right_fringe (struct frame *f, Lisp_Object new_value, Lisp_Object old_value) { int unit = FRAME_COLUMN_WIDTH (f); int old_width = FRAME_RIGHT_FRINGE_WIDTH (f); int new_width; - new_width = (RANGED_INTEGERP (-INT_MAX, new_value, INT_MAX) - ? eabs (XINT (new_value)) : 8); + new_width = (RANGED_FIXNUMP (-INT_MAX, new_value, INT_MAX) + ? eabs (XFIXNUM (new_value)) : 8); if (new_width != old_width) { @@ -4407,7 +4791,7 @@ x_set_right_fringe (struct frame *f, Lisp_Object new_value, Lisp_Object old_valu f->fringe_cols /* Round up. */ = (new_width + FRAME_LEFT_FRINGE_WIDTH (f) + unit - 1) / unit; - if (FRAME_X_WINDOW (f) != 0) + if (FRAME_NATIVE_WINDOW (f) != 0) adjust_frame_size (f, -1, -1, 3, 0, Qright_fringe); SET_FRAME_GARBAGED (f); @@ -4416,25 +4800,24 @@ x_set_right_fringe (struct frame *f, Lisp_Object new_value, Lisp_Object old_valu void -x_set_border_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval) +gui_set_border_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval) { - CHECK_TYPE_RANGED_INTEGER (int, arg); + int border_width = check_integer_range (arg, INT_MIN, INT_MAX); - if (XINT (arg) == f->border_width) + if (border_width == f->border_width) return; - if (FRAME_X_WINDOW (f) != 0) + if (FRAME_NATIVE_WINDOW (f) != 0) error ("Cannot change the border width of a frame"); - f->border_width = XINT (arg); + f->border_width = border_width; } void -x_set_right_divider_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval) +gui_set_right_divider_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval) { int old = FRAME_RIGHT_DIVIDER_WIDTH (f); - CHECK_TYPE_RANGED_INTEGER (int, arg); - int new = max (0, XINT (arg)); + int new = check_int_nonnegative (arg); if (new != old) { f->right_divider_width = new; @@ -4445,11 +4828,10 @@ x_set_right_divider_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval) } void -x_set_bottom_divider_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval) +gui_set_bottom_divider_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval) { int old = FRAME_BOTTOM_DIVIDER_WIDTH (f); - CHECK_TYPE_RANGED_INTEGER (int, arg); - int new = max (0, XINT (arg)); + int new = check_int_nonnegative (arg); if (new != old) { f->bottom_divider_width = new; @@ -4460,7 +4842,7 @@ x_set_bottom_divider_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval } void -x_set_visibility (struct frame *f, Lisp_Object value, Lisp_Object oldval) +gui_set_visibility (struct frame *f, Lisp_Object value, Lisp_Object oldval) { Lisp_Object frame; XSETFRAME (frame, f); @@ -4474,25 +4856,25 @@ x_set_visibility (struct frame *f, Lisp_Object value, Lisp_Object oldval) } void -x_set_autoraise (struct frame *f, Lisp_Object arg, Lisp_Object oldval) +gui_set_autoraise (struct frame *f, Lisp_Object arg, Lisp_Object oldval) { - f->auto_raise = !EQ (Qnil, arg); + f->auto_raise = !NILP (arg); } void -x_set_autolower (struct frame *f, Lisp_Object arg, Lisp_Object oldval) +gui_set_autolower (struct frame *f, Lisp_Object arg, Lisp_Object oldval) { - f->auto_lower = !EQ (Qnil, arg); + f->auto_lower = !NILP (arg); } void -x_set_unsplittable (struct frame *f, Lisp_Object arg, Lisp_Object oldval) +gui_set_unsplittable (struct frame *f, Lisp_Object arg, Lisp_Object oldval) { f->no_split = !NILP (arg); } void -x_set_vertical_scroll_bars (struct frame *f, Lisp_Object arg, Lisp_Object oldval) +gui_set_vertical_scroll_bars (struct frame *f, Lisp_Object arg, Lisp_Object oldval) { if ((EQ (arg, Qleft) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f)) || (EQ (arg, Qright) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (f)) @@ -4512,11 +4894,11 @@ x_set_vertical_scroll_bars (struct frame *f, Lisp_Object arg, Lisp_Object oldval ? vertical_scroll_bar_right : vertical_scroll_bar_none); - /* We set this parameter before creating the X window for the - frame, so we can get the geometry right from the start. + /* We set this parameter before creating the native window for + the frame, so we can get the geometry right from the start. However, if the window hasn't been created yet, we shouldn't - call x_set_window_size. */ - if (FRAME_X_WINDOW (f)) + call set_window_size_hook. */ + if (FRAME_NATIVE_WINDOW (f)) adjust_frame_size (f, -1, -1, 3, 0, Qvertical_scroll_bars); SET_FRAME_GARBAGED (f); @@ -4524,7 +4906,7 @@ x_set_vertical_scroll_bars (struct frame *f, Lisp_Object arg, Lisp_Object oldval } void -x_set_horizontal_scroll_bars (struct frame *f, Lisp_Object arg, Lisp_Object oldval) +gui_set_horizontal_scroll_bars (struct frame *f, Lisp_Object arg, Lisp_Object oldval) { #if USE_HORIZONTAL_SCROLL_BARS if ((NILP (arg) && FRAME_HAS_HORIZONTAL_SCROLL_BARS (f)) @@ -4532,11 +4914,11 @@ x_set_horizontal_scroll_bars (struct frame *f, Lisp_Object arg, Lisp_Object oldv { f->horizontal_scroll_bars = NILP (arg) ? false : true; - /* We set this parameter before creating the X window for the - frame, so we can get the geometry right from the start. + /* We set this parameter before creating the native window for + the frame, so we can get the geometry right from the start. However, if the window hasn't been created yet, we shouldn't - call x_set_window_size. */ - if (FRAME_X_WINDOW (f)) + call set_window_size_hook. */ + if (FRAME_NATIVE_WINDOW (f)) adjust_frame_size (f, -1, -1, 3, 0, Qhorizontal_scroll_bars); SET_FRAME_GARBAGED (f); @@ -4545,25 +4927,26 @@ x_set_horizontal_scroll_bars (struct frame *f, Lisp_Object arg, Lisp_Object oldv } void -x_set_scroll_bar_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval) +gui_set_scroll_bar_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval) { int unit = FRAME_COLUMN_WIDTH (f); - if (NILP (arg)) + if (RANGED_FIXNUMP (1, arg, INT_MAX) + && XFIXNAT (arg) != FRAME_CONFIG_SCROLL_BAR_WIDTH (f)) { - x_set_scroll_bar_default_width (f); - - if (FRAME_X_WINDOW (f)) + FRAME_CONFIG_SCROLL_BAR_WIDTH (f) = XFIXNAT (arg); + FRAME_CONFIG_SCROLL_BAR_COLS (f) = (XFIXNAT (arg) + unit - 1) / unit; + if (FRAME_NATIVE_WINDOW (f)) adjust_frame_size (f, -1, -1, 3, 0, Qscroll_bar_width); SET_FRAME_GARBAGED (f); } - else if (RANGED_INTEGERP (1, arg, INT_MAX) - && XFASTINT (arg) != FRAME_CONFIG_SCROLL_BAR_WIDTH (f)) + else { - FRAME_CONFIG_SCROLL_BAR_WIDTH (f) = XFASTINT (arg); - FRAME_CONFIG_SCROLL_BAR_COLS (f) = (XFASTINT (arg) + unit - 1) / unit; - if (FRAME_X_WINDOW (f)) + if (FRAME_TERMINAL (f)->set_scroll_bar_default_width_hook) + FRAME_TERMINAL (f)->set_scroll_bar_default_width_hook (f); + + if (FRAME_NATIVE_WINDOW (f)) adjust_frame_size (f, -1, -1, 3, 0, Qscroll_bar_width); SET_FRAME_GARBAGED (f); @@ -4574,26 +4957,27 @@ x_set_scroll_bar_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval) } void -x_set_scroll_bar_height (struct frame *f, Lisp_Object arg, Lisp_Object oldval) +gui_set_scroll_bar_height (struct frame *f, Lisp_Object arg, Lisp_Object oldval) { #if USE_HORIZONTAL_SCROLL_BARS int unit = FRAME_LINE_HEIGHT (f); - if (NILP (arg)) + if (RANGED_FIXNUMP (1, arg, INT_MAX) + && XFIXNAT (arg) != FRAME_CONFIG_SCROLL_BAR_HEIGHT (f)) { - x_set_scroll_bar_default_height (f); - - if (FRAME_X_WINDOW (f)) + FRAME_CONFIG_SCROLL_BAR_HEIGHT (f) = XFIXNAT (arg); + FRAME_CONFIG_SCROLL_BAR_LINES (f) = (XFIXNAT (arg) + unit - 1) / unit; + if (FRAME_NATIVE_WINDOW (f)) adjust_frame_size (f, -1, -1, 3, 0, Qscroll_bar_height); SET_FRAME_GARBAGED (f); } - else if (RANGED_INTEGERP (1, arg, INT_MAX) - && XFASTINT (arg) != FRAME_CONFIG_SCROLL_BAR_HEIGHT (f)) + else { - FRAME_CONFIG_SCROLL_BAR_HEIGHT (f) = XFASTINT (arg); - FRAME_CONFIG_SCROLL_BAR_LINES (f) = (XFASTINT (arg) + unit - 1) / unit; - if (FRAME_X_WINDOW (f)) + if (FRAME_TERMINAL (f)->set_scroll_bar_default_height_hook) + FRAME_TERMINAL (f)->set_scroll_bar_default_height_hook (f); + + if (FRAME_NATIVE_WINDOW (f)) adjust_frame_size (f, -1, -1, 3, 0, Qscroll_bar_height); SET_FRAME_GARBAGED (f); @@ -4605,7 +4989,7 @@ x_set_scroll_bar_height (struct frame *f, Lisp_Object arg, Lisp_Object oldval) } void -x_set_alpha (struct frame *f, Lisp_Object arg, Lisp_Object oldval) +gui_set_alpha (struct frame *f, Lisp_Object arg, Lisp_Object oldval) { double alpha = 1.0; double newval[2]; @@ -4631,11 +5015,11 @@ x_set_alpha (struct frame *f, Lisp_Object arg, Lisp_Object oldval) if (! (0 <= alpha && alpha <= 1.0)) args_out_of_range (make_float (0.0), make_float (1.0)); } - else if (INTEGERP (item)) + else if (FIXNUMP (item)) { - EMACS_INT ialpha = XINT (item); + EMACS_INT ialpha = XFIXNUM (item); if (! (0 <= ialpha && ialpha <= 100)) - args_out_of_range (make_number (0), make_number (100)); + args_out_of_range (make_fixnum (0), make_fixnum (100)); alpha = ialpha / 100.0; } else @@ -4646,39 +5030,67 @@ x_set_alpha (struct frame *f, Lisp_Object arg, Lisp_Object oldval) for (i = 0; i < 2; i++) f->alpha[i] = newval[i]; -#if defined (HAVE_X_WINDOWS) || defined (HAVE_NTGUI) || defined (NS_IMPL_COCOA) - block_input (); - x_set_frame_alpha (f); - unblock_input (); -#endif - - return; + if (FRAME_TERMINAL (f)->set_frame_alpha_hook) + { + block_input (); + FRAME_TERMINAL (f)->set_frame_alpha_hook (f); + unblock_input (); + } } +void +gui_set_alpha_background (struct frame *f, Lisp_Object arg, Lisp_Object oldval) +{ + double alpha = 1.0; + + if (NILP (arg)) + alpha = 1.0; + else if (FLOATP (arg)) + { + alpha = XFLOAT_DATA (arg); + if (! (0 <= alpha && alpha <= 1.0)) + args_out_of_range (make_float (0.0), make_float (1.0)); + } + else if (FIXNUMP (arg)) + { + EMACS_INT ialpha = XFIXNUM (arg); + if (! (0 <= ialpha && ialpha <= 100)) + args_out_of_range (make_fixnum (0), make_fixnum (100)); + alpha = ialpha / 100.0; + } + else + wrong_type_argument (Qnumberp, arg); + + f->alpha_background = alpha; + + recompute_basic_faces (f); + SET_FRAME_GARBAGED (f); +} /** - * x_set_no_special_glyphs: + * gui_set_no_special_glyphs: * * Set frame F's `no-special-glyphs' parameter which, if non-nil, * suppresses the display of truncation and continuation glyphs * outside fringes. */ void -x_set_no_special_glyphs (struct frame *f, Lisp_Object new_value, Lisp_Object old_value) +gui_set_no_special_glyphs (struct frame *f, Lisp_Object new_value, Lisp_Object old_value) { if (!EQ (new_value, old_value)) FRAME_NO_SPECIAL_GLYPHS (f) = !NILP (new_value); } -#ifndef HAVE_NS - /* Non-zero if mouse is grabbed on DPYINFO and we know the frame where it is. */ -bool x_mouse_grabbed (Display_Info *dpyinfo) +bool +gui_mouse_grabbed (Display_Info *dpyinfo) { - return (dpyinfo->grabbed + return ((dpyinfo->grabbed + || (dpyinfo->terminal->any_grab_hook + && dpyinfo->terminal->any_grab_hook (dpyinfo))) && dpyinfo->last_mouse_frame && FRAME_LIVE_P (dpyinfo->last_mouse_frame)); } @@ -4687,7 +5099,7 @@ bool x_mouse_grabbed (Display_Info *dpyinfo) on DPYINFO using saved frame and mouse position. */ void -x_redo_mouse_highlight (Display_Info *dpyinfo) +gui_redo_mouse_highlight (Display_Info *dpyinfo) { if (dpyinfo->last_mouse_motion_frame && FRAME_LIVE_P (dpyinfo->last_mouse_motion_frame)) @@ -4696,8 +5108,6 @@ x_redo_mouse_highlight (Display_Info *dpyinfo) dpyinfo->last_mouse_motion_y); } -#endif /* HAVE_NS */ - /* Subroutines of creating an X frame. */ /* Make sure that Vx_resource_name is set to a reasonable value. @@ -4769,11 +5179,13 @@ validate_x_resource_name (void) } } -/* Get specified attribute from resource database RDB. +/* Get a GUI resource, like Fx_get_resource, but for display DPYINFO. See Fx_get_resource below for other parameters. */ -static Lisp_Object -xrdb_get_resource (XrmDatabase rdb, Lisp_Object attribute, Lisp_Object class, Lisp_Object component, Lisp_Object subclass) +Lisp_Object +gui_display_get_resource (Display_Info *dpyinfo, Lisp_Object attribute, + Lisp_Object class, Lisp_Object component, + Lisp_Object subclass) { CHECK_STRING (attribute); CHECK_STRING (class); @@ -4824,7 +5236,10 @@ xrdb_get_resource (XrmDatabase rdb, Lisp_Object attribute, Lisp_Object class, Li *nz++ = '.'; lispstpcpy (nz, attribute); - char *value = x_get_string_resource (rdb, name_key, class_key); + const char *value = + dpyinfo->terminal->get_string_resource_hook (&dpyinfo->rdb, + name_key, + class_key); SAFE_FREE(); if (value && *value) @@ -4849,28 +5264,17 @@ and the class is `Emacs.CLASS.SUBCLASS'. */) { check_window_system (NULL); - return xrdb_get_resource (check_x_display_info (Qnil)->xrdb, - attribute, class, component, subclass); -} - -/* Get an X resource, like Fx_get_resource, but for display DPYINFO. */ - -Lisp_Object -display_x_get_resource (Display_Info *dpyinfo, Lisp_Object attribute, - Lisp_Object class, Lisp_Object component, - Lisp_Object subclass) -{ - return xrdb_get_resource (dpyinfo->xrdb, - attribute, class, component, subclass); + return gui_display_get_resource (check_x_display_info (Qnil), + attribute, class, component, subclass); } #if defined HAVE_X_WINDOWS && !defined USE_X_TOOLKIT && !defined USE_GTK /* Used when C code wants a resource value. */ /* Called from oldXMenu/Create.c. */ -char * +const char * x_get_resource_string (const char *attribute, const char *class) { - char *result; + const char *result; struct frame *sf = SELECTED_FRAME (); ptrdiff_t invocation_namelen = SBYTES (Vinvocation_name); USE_SAFE_ALLOCA; @@ -4881,11 +5285,10 @@ x_get_resource_string (const char *attribute, const char *class) ptrdiff_t class_keysize = sizeof (EMACS_CLASS) - 1 + strlen (class) + 2; char *name_key = SAFE_ALLOCA (name_keysize + class_keysize); char *class_key = name_key + name_keysize; - esprintf (name_key, "%s.%s", SSDATA (Vinvocation_name), attribute); sprintf (class_key, "%s.%s", EMACS_CLASS, class); - result = x_get_string_resource (FRAME_DISPLAY_INFO (sf)->xrdb, + result = x_get_string_resource (&FRAME_DISPLAY_INFO (sf)->rdb, name_key, class_key); SAFE_FREE (); return result; @@ -4894,18 +5297,21 @@ x_get_resource_string (const char *attribute, const char *class) /* Return the value of parameter PARAM. - First search ALIST, then Vdefault_frame_alist, then the X defaults - database, using ATTRIBUTE as the attribute name and CLASS as its class. + First search ALIST, then Vdefault_frame_alist, then the GUI + resource database, using ATTRIBUTE as the attribute name and CLASS + as its class. Convert the resource to the type specified by desired_type. If no default is specified, return Qunbound. If you call - x_get_arg, make sure you deal with Qunbound in a reasonable way, - and don't let it get stored in any Lisp-visible variables! */ + gui_display_get_arg, make sure you deal with Qunbound in a + reasonable way, and don't let it get stored in any Lisp-visible + variables! */ Lisp_Object -x_get_arg (Display_Info *dpyinfo, Lisp_Object alist, Lisp_Object param, - const char *attribute, const char *class, enum resource_types type) +gui_display_get_arg (Display_Info *dpyinfo, Lisp_Object alist, Lisp_Object param, + const char *attribute, const char *class, + enum resource_types type) { Lisp_Object tem; @@ -4929,13 +5335,13 @@ x_get_arg (Display_Info *dpyinfo, Lisp_Object alist, Lisp_Object param, /* If it wasn't specified in ALIST or the Lisp-level defaults, look in the X resources. */ - if (EQ (tem, Qnil)) + if (NILP (tem)) { if (attribute && dpyinfo) { AUTO_STRING (at, attribute); AUTO_STRING (cl, class); - tem = display_x_get_resource (dpyinfo, at, cl, Qnil, Qnil); + tem = gui_display_get_resource (dpyinfo, at, cl, Qnil, Qnil); if (NILP (tem)) return Qunbound; @@ -4943,13 +5349,13 @@ x_get_arg (Display_Info *dpyinfo, Lisp_Object alist, Lisp_Object param, switch (type) { case RES_TYPE_NUMBER: - return make_number (atoi (SSDATA (tem))); + return make_fixnum (atoi (SSDATA (tem))); case RES_TYPE_BOOLEAN_NUMBER: if (!strcmp (SSDATA (tem), "on") || !strcmp (SSDATA (tem), "true")) - return make_number (1); - return make_number (atoi (SSDATA (tem))); + return make_fixnum (1); + return make_fixnum (atoi (SSDATA (tem))); break; case RES_TYPE_FLOAT: @@ -5002,27 +5408,27 @@ x_get_arg (Display_Info *dpyinfo, Lisp_Object alist, Lisp_Object param, } static Lisp_Object -x_frame_get_arg (struct frame *f, Lisp_Object alist, Lisp_Object param, - const char *attribute, const char *class, - enum resource_types type) +gui_frame_get_arg (struct frame *f, Lisp_Object alist, Lisp_Object param, + const char *attribute, const char *class, + enum resource_types type) { - return x_get_arg (FRAME_DISPLAY_INFO (f), - alist, param, attribute, class, type); + return gui_display_get_arg (FRAME_DISPLAY_INFO (f), + alist, param, attribute, class, type); } -/* Like x_frame_get_arg, but also record the value in f->param_alist. */ +/* Like gui_frame_get_arg, but also record the value in f->param_alist. */ Lisp_Object -x_frame_get_and_record_arg (struct frame *f, Lisp_Object alist, - Lisp_Object param, - const char *attribute, const char *class, - enum resource_types type) +gui_frame_get_and_record_arg (struct frame *f, Lisp_Object alist, + Lisp_Object param, + const char *attribute, const char *class, + enum resource_types type) { Lisp_Object value; - value = x_get_arg (FRAME_DISPLAY_INFO (f), alist, param, - attribute, class, type); - if (! NILP (value) && ! EQ (value, Qunbound)) + value = gui_display_get_arg (FRAME_DISPLAY_INFO (f), alist, param, + attribute, class, type); + if (! NILP (value) && ! BASE_EQ (value, Qunbound)) store_frame_param (f, param, value); return value; @@ -5036,17 +5442,17 @@ x_frame_get_and_record_arg (struct frame *f, Lisp_Object alist, If that is not found either, use the value DEFLT. */ Lisp_Object -x_default_parameter (struct frame *f, Lisp_Object alist, Lisp_Object prop, - Lisp_Object deflt, const char *xprop, const char *xclass, - enum resource_types type) +gui_default_parameter (struct frame *f, Lisp_Object alist, Lisp_Object prop, + Lisp_Object deflt, const char *xprop, const char *xclass, + enum resource_types type) { Lisp_Object tem; - tem = x_frame_get_arg (f, alist, prop, xprop, xclass, type); - if (EQ (tem, Qunbound)) + tem = gui_frame_get_arg (f, alist, prop, xprop, xclass, type); + if (BASE_EQ (tem, Qunbound)) tem = deflt; AUTO_FRAME_ARG (arg, prop, tem); - x_set_frame_parameters (f, arg); + gui_set_frame_parameters (f, arg); return tem; } @@ -5160,9 +5566,11 @@ or a list (- N) meaning -N pixels relative to bottom/right corner. On Nextstep, this just calls `ns-parse-geometry'. */) (Lisp_Object string) { - int geometry, x, y; + /* x and y don't need initialization, as they are not accessed + unless XParseGeometry sets them, in which case it always returns + a non-zero value. */ + int x UNINIT, y UNINIT; unsigned int width, height; - Lisp_Object result; CHECK_STRING (string); @@ -5170,19 +5578,19 @@ On Nextstep, this just calls `ns-parse-geometry'. */) if (strchr (SSDATA (string), ' ') != NULL) return call1 (Qns_parse_geometry, string); #endif - geometry = XParseGeometry (SSDATA (string), - &x, &y, &width, &height); - result = Qnil; + int geometry = XParseGeometry (SSDATA (string), + &x, &y, &width, &height); + Lisp_Object result = Qnil; if (geometry & XValue) { Lisp_Object element; if (x >= 0 && (geometry & XNegative)) - element = list3 (Qleft, Qminus, make_number (-x)); + element = list3 (Qleft, Qminus, make_fixnum (-x)); else if (x < 0 && ! (geometry & XNegative)) - element = list3 (Qleft, Qplus, make_number (x)); + element = list3 (Qleft, Qplus, make_fixnum (x)); else - element = Fcons (Qleft, make_number (x)); + element = Fcons (Qleft, make_fixnum (x)); result = Fcons (element, result); } @@ -5191,18 +5599,18 @@ On Nextstep, this just calls `ns-parse-geometry'. */) Lisp_Object element; if (y >= 0 && (geometry & YNegative)) - element = list3 (Qtop, Qminus, make_number (-y)); + element = list3 (Qtop, Qminus, make_fixnum (-y)); else if (y < 0 && ! (geometry & YNegative)) - element = list3 (Qtop, Qplus, make_number (y)); + element = list3 (Qtop, Qplus, make_fixnum (y)); else - element = Fcons (Qtop, make_number (y)); + element = Fcons (Qtop, make_fixnum (y)); result = Fcons (element, result); } if (geometry & WidthValue) - result = Fcons (Fcons (Qwidth, make_number (width)), result); + result = Fcons (Fcons (Qwidth, make_fixnum (width)), result); if (geometry & HeightValue) - result = Fcons (Fcons (Qheight, make_number (height)), result); + result = Fcons (Fcons (Qheight, make_fixnum (height)), result); return result; } @@ -5217,30 +5625,56 @@ On Nextstep, this just calls `ns-parse-geometry'. */) This function does not make the coordinates positive. */ -#define DEFAULT_ROWS 36 -#define DEFAULT_COLS 80 - long -x_figure_window_size (struct frame *f, Lisp_Object parms, bool toolbar_p, int *x_width, int *x_height) +gui_figure_window_size (struct frame *f, Lisp_Object parms, bool tabbar_p, + bool toolbar_p) { Lisp_Object height, width, user_size, top, left, user_position; long window_prompting = 0; Display_Info *dpyinfo = FRAME_DISPLAY_INFO (f); int parent_done = -1, outer_done = -1; - - /* Default values if we fall through. - Actually, if that happens we should get - window manager prompting. */ - SET_FRAME_WIDTH (f, DEFAULT_COLS * FRAME_COLUMN_WIDTH (f)); - SET_FRAME_COLS (f, DEFAULT_COLS); - SET_FRAME_HEIGHT (f, DEFAULT_ROWS * FRAME_LINE_HEIGHT (f)); - SET_FRAME_LINES (f, DEFAULT_ROWS); + int text_width = 80 * FRAME_COLUMN_WIDTH (f); + int text_height = 36 * FRAME_LINE_HEIGHT (f); /* Window managers expect that if program-specified positions are not (0,0), they're intentional, not defaults. */ f->top_pos = 0; f->left_pos = 0; + /* Calculate a tab bar height so that the user gets a text display + area of the size he specified with -g or via .Xdefaults. Later + changes of the tab bar height don't change the frame size. This + is done so that users can create tall Emacs frames without having + to guess how tall the tab bar will get. */ + if (tabbar_p && FRAME_TAB_BAR_LINES (f)) + { + if (frame_default_tab_bar_height) + /* A default tab bar height was already set by the display code + for some other frame, use that. */ + FRAME_TAB_BAR_HEIGHT (f) = frame_default_tab_bar_height; + else + /* Calculate the height from various other settings. For some + reason, these are usually off by 2 hence of no use. */ + { + int margin, relief; + + relief = (tab_bar_button_relief < 0 + ? DEFAULT_TAB_BAR_BUTTON_RELIEF + : min (tab_bar_button_relief, 1000000)); + + if (RANGED_FIXNUMP (1, Vtab_bar_button_margin, INT_MAX)) + margin = XFIXNAT (Vtab_bar_button_margin); + else if (CONSP (Vtab_bar_button_margin) + && RANGED_FIXNUMP (1, XCDR (Vtab_bar_button_margin), INT_MAX)) + margin = XFIXNAT (XCDR (Vtab_bar_button_margin)); + else + margin = 0; + + FRAME_TAB_BAR_HEIGHT (f) + = DEFAULT_TAB_BAR_IMAGE_HEIGHT + 2 * margin + 2 * relief; + } + } + /* Calculate a tool bar height so that the user gets a text display area of the size he specified with -g or via .Xdefaults. Later changes of the tool bar height don't change the frame size. This @@ -5254,15 +5688,15 @@ x_figure_window_size (struct frame *f, Lisp_Object parms, bool toolbar_p, int *x { int margin, relief; - relief = (tool_bar_button_relief >= 0 - ? tool_bar_button_relief - : DEFAULT_TOOL_BAR_BUTTON_RELIEF); + relief = (tool_bar_button_relief < 0 + ? DEFAULT_TOOL_BAR_BUTTON_RELIEF + : min (tool_bar_button_relief, 1000000)); - if (RANGED_INTEGERP (1, Vtool_bar_button_margin, INT_MAX)) - margin = XFASTINT (Vtool_bar_button_margin); + if (RANGED_FIXNUMP (1, Vtool_bar_button_margin, INT_MAX)) + margin = XFIXNAT (Vtool_bar_button_margin); else if (CONSP (Vtool_bar_button_margin) - && RANGED_INTEGERP (1, XCDR (Vtool_bar_button_margin), INT_MAX)) - margin = XFASTINT (XCDR (Vtool_bar_button_margin)); + && RANGED_FIXNUMP (1, XCDR (Vtool_bar_button_margin), INT_MAX)) + margin = XFIXNAT (XCDR (Vtool_bar_button_margin)); else margin = 0; @@ -5273,23 +5707,22 @@ x_figure_window_size (struct frame *f, Lisp_Object parms, bool toolbar_p, int *x /* Ensure that earlier new_width and new_height settings won't override what we specify below. */ - f->new_width = f->new_height = 0; + f->new_width = f->new_height = -1; - height = x_get_arg (dpyinfo, parms, Qheight, 0, 0, RES_TYPE_NUMBER); - width = x_get_arg (dpyinfo, parms, Qwidth, 0, 0, RES_TYPE_NUMBER); - if (!EQ (width, Qunbound) || !EQ (height, Qunbound)) + height = gui_display_get_arg (dpyinfo, parms, Qheight, 0, 0, RES_TYPE_NUMBER); + width = gui_display_get_arg (dpyinfo, parms, Qwidth, 0, 0, RES_TYPE_NUMBER); + if (!BASE_EQ (width, Qunbound) || !BASE_EQ (height, Qunbound)) { - if (!EQ (width, Qunbound)) + if (!BASE_EQ (width, Qunbound)) { if (CONSP (width) && EQ (XCAR (width), Qtext_pixels)) { - CHECK_NUMBER (XCDR (width)); - if ((XINT (XCDR (width)) < 0 || XINT (XCDR (width)) > INT_MAX)) + CHECK_FIXNUM (XCDR (width)); + if ((XFIXNUM (XCDR (width)) < 0 || XFIXNUM (XCDR (width)) > INT_MAX)) xsignal1 (Qargs_out_of_range, XCDR (width)); - SET_FRAME_WIDTH (f, XINT (XCDR (width))); + text_width = XFIXNUM (XCDR (width)); f->inhibit_horizontal_resize = true; - *x_width = XINT (XCDR (width)); } else if (FLOATP (width)) { @@ -5303,30 +5736,29 @@ x_figure_window_size (struct frame *f, Lisp_Object parms, bool toolbar_p, int *x &parent_done, &outer_done, -1); if (new_width > -1) - SET_FRAME_WIDTH (f, new_width); + text_width = new_width; } } else { - CHECK_NUMBER (width); - if ((XINT (width) < 0 || XINT (width) > INT_MAX)) + CHECK_FIXNUM (width); + if ((XFIXNUM (width) < 0 || XFIXNUM (width) > INT_MAX)) xsignal1 (Qargs_out_of_range, width); - SET_FRAME_WIDTH (f, XINT (width) * FRAME_COLUMN_WIDTH (f)); + text_width = XFIXNUM (width) * FRAME_COLUMN_WIDTH (f); } } - if (!EQ (height, Qunbound)) + if (!BASE_EQ (height, Qunbound)) { if (CONSP (height) && EQ (XCAR (height), Qtext_pixels)) { - CHECK_NUMBER (XCDR (height)); - if ((XINT (XCDR (height)) < 0 || XINT (XCDR (height)) > INT_MAX)) + CHECK_FIXNUM (XCDR (height)); + if ((XFIXNUM (XCDR (height)) < 0 || XFIXNUM (XCDR (height)) > INT_MAX)) xsignal1 (Qargs_out_of_range, XCDR (height)); - SET_FRAME_HEIGHT (f, XINT (XCDR (height))); + text_height = XFIXNUM (XCDR (height)); f->inhibit_vertical_resize = true; - *x_height = XINT (XCDR (height)); } else if (FLOATP (height)) { @@ -5340,30 +5772,35 @@ x_figure_window_size (struct frame *f, Lisp_Object parms, bool toolbar_p, int *x &parent_done, &outer_done, -1); if (new_height > -1) - SET_FRAME_HEIGHT (f, new_height); + text_height = new_height; } } else { - CHECK_NUMBER (height); - if ((XINT (height) < 0) || (XINT (height) > INT_MAX)) + CHECK_FIXNUM (height); + if ((XFIXNUM (height) < 0) || (XFIXNUM (height) > INT_MAX)) xsignal1 (Qargs_out_of_range, height); - SET_FRAME_HEIGHT (f, XINT (height) * FRAME_LINE_HEIGHT (f)); + text_height = XFIXNUM (height) * FRAME_LINE_HEIGHT (f); } } - user_size = x_get_arg (dpyinfo, parms, Quser_size, 0, 0, RES_TYPE_NUMBER); - if (!NILP (user_size) && !EQ (user_size, Qunbound)) + user_size = gui_display_get_arg (dpyinfo, parms, Quser_size, 0, 0, + RES_TYPE_NUMBER); + if (!NILP (user_size) && !BASE_EQ (user_size, Qunbound)) window_prompting |= USSize; else window_prompting |= PSize; } - top = x_get_arg (dpyinfo, parms, Qtop, 0, 0, RES_TYPE_NUMBER); - left = x_get_arg (dpyinfo, parms, Qleft, 0, 0, RES_TYPE_NUMBER); - user_position = x_get_arg (dpyinfo, parms, Quser_position, 0, 0, RES_TYPE_NUMBER); - if (! EQ (top, Qunbound) || ! EQ (left, Qunbound)) + adjust_frame_size (f, text_width, text_height, 5, false, + Qgui_figure_window_size); + + top = gui_display_get_arg (dpyinfo, parms, Qtop, 0, 0, RES_TYPE_NUMBER); + left = gui_display_get_arg (dpyinfo, parms, Qleft, 0, 0, RES_TYPE_NUMBER); + user_position = gui_display_get_arg (dpyinfo, parms, Quser_position, 0, 0, + RES_TYPE_NUMBER); + if (! BASE_EQ (top, Qunbound) || ! BASE_EQ (left, Qunbound)) { if (EQ (top, Qminus)) { @@ -5372,26 +5809,25 @@ x_figure_window_size (struct frame *f, Lisp_Object parms, bool toolbar_p, int *x } else if (CONSP (top) && EQ (XCAR (top), Qminus) && CONSP (XCDR (top)) - && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (top)), INT_MAX)) + && RANGED_FIXNUMP (-INT_MAX, XCAR (XCDR (top)), INT_MAX)) { - f->top_pos = - XINT (XCAR (XCDR (top))); + f->top_pos = - XFIXNUM (XCAR (XCDR (top))); window_prompting |= YNegative; } else if (CONSP (top) && EQ (XCAR (top), Qplus) && CONSP (XCDR (top)) - && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (top)))) + && TYPE_RANGED_FIXNUMP (int, XCAR (XCDR (top)))) { - f->top_pos = XINT (XCAR (XCDR (top))); + f->top_pos = XFIXNUM (XCAR (XCDR (top))); } else if (FLOATP (top)) f->top_pos = frame_float (f, top, FRAME_FLOAT_TOP, &parent_done, &outer_done, 0); - else if (EQ (top, Qunbound)) + else if (BASE_EQ (top, Qunbound)) f->top_pos = 0; else { - CHECK_TYPE_RANGED_INTEGER (int, top); - f->top_pos = XINT (top); + f->top_pos = check_integer_range (top, INT_MIN, INT_MAX); if (f->top_pos < 0) window_prompting |= YNegative; } @@ -5403,31 +5839,30 @@ x_figure_window_size (struct frame *f, Lisp_Object parms, bool toolbar_p, int *x } else if (CONSP (left) && EQ (XCAR (left), Qminus) && CONSP (XCDR (left)) - && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (left)), INT_MAX)) + && RANGED_FIXNUMP (-INT_MAX, XCAR (XCDR (left)), INT_MAX)) { - f->left_pos = - XINT (XCAR (XCDR (left))); + f->left_pos = - XFIXNUM (XCAR (XCDR (left))); window_prompting |= XNegative; } else if (CONSP (left) && EQ (XCAR (left), Qplus) && CONSP (XCDR (left)) - && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (left)))) + && TYPE_RANGED_FIXNUMP (int, XCAR (XCDR (left)))) { - f->left_pos = XINT (XCAR (XCDR (left))); + f->left_pos = XFIXNUM (XCAR (XCDR (left))); } else if (FLOATP (left)) f->left_pos = frame_float (f, left, FRAME_FLOAT_LEFT, &parent_done, &outer_done, 0); - else if (EQ (left, Qunbound)) + else if (BASE_EQ (left, Qunbound)) f->left_pos = 0; else { - CHECK_TYPE_RANGED_INTEGER (int, left); - f->left_pos = XINT (left); + f->left_pos = check_integer_range (left, INT_MIN, INT_MAX); if (f->left_pos < 0) window_prompting |= XNegative; } - if (!NILP (user_position) && ! EQ (user_position, Qunbound)) + if (!NILP (user_position) && ! BASE_EQ (user_position, Qunbound)) window_prompting |= USPosition; else window_prompting |= PPosition; @@ -5495,7 +5930,18 @@ selected frame. This is useful when `make-pointer-invisible' is set. */) return decode_any_frame (frame)->pointer_invisible ? Qnil : Qt; } +DEFUN ("frame--set-was-invisible", Fframe__set_was_invisible, + Sframe__set_was_invisible, 2, 2, 0, + doc: /* Set FRAME's was-invisible flag if WAS-INVISIBLE is non-nil. +This function is for internal use only. */) + (Lisp_Object frame, Lisp_Object was_invisible) +{ + struct frame *f = decode_live_frame (frame); + + f->was_invisible = !NILP (was_invisible); + return f->was_invisible ? Qt : Qnil; +} /*********************************************************************** Multimonitor data @@ -5503,8 +5949,8 @@ selected frame. This is useful when `make-pointer-invisible' is set. */) #ifdef HAVE_WINDOW_SYSTEM -# if (defined HAVE_NS \ - || (!defined USE_GTK && (defined HAVE_XINERAMA || defined HAVE_XRANDR))) +# if (defined USE_GTK || defined HAVE_PGTK || defined HAVE_NS || defined HAVE_XINERAMA \ + || defined HAVE_XRANDR) void free_monitors (struct MonitorInfo *monitors, int n_monitors) { @@ -5541,6 +5987,10 @@ make_monitor_attribute_list (struct MonitorInfo *monitors, attributes); attributes = Fcons (Fcons (Qframes, AREF (monitor_frames, i)), attributes); +#ifdef HAVE_PGTK + attributes = Fcons (Fcons (Qscale_factor, make_float (mi->scale_factor)), + attributes); +#endif attributes = Fcons (Fcons (Qmm_size, list2i (mi->mm_width, mi->mm_height)), attributes); @@ -5569,13 +6019,33 @@ make_monitor_attribute_list (struct MonitorInfo *monitors, Initialization ***********************************************************************/ +static void init_frame_once_for_pdumper (void); + +void +init_frame_once (void) +{ + staticpro (&Vframe_list); + staticpro (&selected_frame); + PDUMPER_IGNORE (last_nonminibuf_frame); + Vframe_list = Qnil; + selected_frame = Qnil; + pdumper_do_now_and_after_load (init_frame_once_for_pdumper); +} + +static void +init_frame_once_for_pdumper (void) +{ + PDUMPER_RESET_LV (Vframe_list, Qnil); + PDUMPER_RESET_LV (selected_frame, Qnil); +} + void syms_of_frame (void) { DEFSYM (Qframep, "framep"); DEFSYM (Qframe_live_p, "frame-live-p"); DEFSYM (Qframe_windows_min_size, "frame-windows-min-size"); - DEFSYM (Qdisplay_monitor_attributes_list, "display-monitor-attributes-list"); + DEFSYM (Qframe_monitor_attributes, "frame-monitor-attributes"); DEFSYM (Qwindow__pixel_to_total, "window--pixel-to-total"); DEFSYM (Qexplicit_name, "explicit-name"); DEFSYM (Qheight, "height"); @@ -5610,6 +6080,8 @@ syms_of_frame (void) DEFSYM (Qw32, "w32"); DEFSYM (Qpc, "pc"); DEFSYM (Qns, "ns"); + DEFSYM (Qpgtk, "pgtk"); + DEFSYM (Qhaiku, "haiku"); DEFSYM (Qvisible, "visible"); DEFSYM (Qbuffer_predicate, "buffer-predicate"); DEFSYM (Qbuffer_list, "buffer-list"); @@ -5627,11 +6099,15 @@ syms_of_frame (void) DEFSYM (Qfullheight, "fullheight"); DEFSYM (Qfullboth, "fullboth"); DEFSYM (Qmaximized, "maximized"); + DEFSYM (Qshaded, "shaded"); DEFSYM (Qx_resource_name, "x-resource-name"); DEFSYM (Qx_frame_parameter, "x-frame-parameter"); DEFSYM (Qworkarea, "workarea"); DEFSYM (Qmm_size, "mm-size"); +#ifdef HAVE_PGTK + DEFSYM (Qscale_factor, "scale-factor"); +#endif DEFSYM (Qframes, "frames"); DEFSYM (Qsource, "source"); @@ -5645,38 +6121,20 @@ syms_of_frame (void) DEFSYM (Qtitle_bar_size, "title-bar-size"); DEFSYM (Qmenu_bar_external, "menu-bar-external"); DEFSYM (Qmenu_bar_size, "menu-bar-size"); + DEFSYM (Qtab_bar_size, "tab-bar-size"); DEFSYM (Qtool_bar_external, "tool-bar-external"); DEFSYM (Qtool_bar_size, "tool-bar-size"); - /* The following are used for frame_size_history. */ - DEFSYM (Qadjust_frame_size_1, "adjust-frame-size-1"); - DEFSYM (Qadjust_frame_size_2, "adjust-frame-size-2"); - DEFSYM (Qadjust_frame_size_3, "adjust-frame-size-3"); - DEFSYM (Qx_set_frame_parameters, "x-set-frame-parameters"); - DEFSYM (QEmacsFrameResize, "EmacsFrameResize"); - DEFSYM (Qset_frame_size, "set-frame-size"); - DEFSYM (Qframe_inhibit_resize, "frame-inhibit-resize"); - DEFSYM (Qx_set_fullscreen, "x-set-fullscreen"); - DEFSYM (Qx_check_fullscreen, "x-check-fullscreen"); - DEFSYM (Qxg_frame_resized, "xg-frame-resized"); - DEFSYM (Qxg_frame_set_char_size_1, "xg-frame-set-char-size-1"); - DEFSYM (Qxg_frame_set_char_size_2, "xg-frame-set-char-size-2"); - DEFSYM (Qxg_frame_set_char_size_3, "xg-frame-set-char-size-3"); - DEFSYM (Qx_set_window_size_1, "x-set-window-size-1"); - DEFSYM (Qx_set_window_size_2, "x-set-window-size-2"); - DEFSYM (Qx_set_window_size_3, "x-set-window-size-3"); - DEFSYM (Qxg_change_toolbar_position, "xg-change-toolbar-position"); - DEFSYM (Qx_net_wm_state, "x-net-wm-state"); - DEFSYM (Qx_handle_net_wm_state, "x-handle-net-wm-state"); - DEFSYM (Qtb_size_cb, "tb-size-cb"); - DEFSYM (Qupdate_frame_tool_bar, "update-frame-tool-bar"); - DEFSYM (Qfree_frame_tool_bar, "free-frame-tool-bar"); - DEFSYM (Qx_set_menu_bar_lines, "x-set-menu-bar-lines"); - DEFSYM (Qchange_frame_size, "change-frame-size"); - DEFSYM (Qxg_frame_set_char_size, "xg-frame-set-char-size"); - DEFSYM (Qset_window_configuration, "set-window-configuration"); - DEFSYM (Qx_create_frame_1, "x-create-frame-1"); - DEFSYM (Qx_create_frame_2, "x-create-frame-2"); - DEFSYM (Qterminal_frame, "terminal-frame"); + /* The following are passed to adjust_frame_size. */ + DEFSYM (Qx_set_menu_bar_lines, "x_set_menu_bar_lines"); + DEFSYM (Qchange_frame_size, "change_frame_size"); + DEFSYM (Qxg_frame_set_char_size, "xg_frame_set_char_size"); + DEFSYM (Qx_set_window_size_1, "x_set_window_size_1"); + DEFSYM (Qset_window_configuration, "set_window_configuration"); + DEFSYM (Qx_create_frame_1, "x_create_frame_1"); + DEFSYM (Qx_create_frame_2, "x_create_frame_2"); + DEFSYM (Qgui_figure_window_size, "gui_figure_window_size"); + DEFSYM (Qtip_frame, "tip_frame"); + DEFSYM (Qterminal_frame, "terminal_frame"); #ifdef HAVE_NS DEFSYM (Qns_parse_geometry, "ns-parse-geometry"); @@ -5687,6 +6145,7 @@ syms_of_frame (void) #endif DEFSYM (Qalpha, "alpha"); + DEFSYM (Qalpha_background, "alpha-background"); DEFSYM (Qauto_lower, "auto-lower"); DEFSYM (Qauto_raise, "auto-raise"); DEFSYM (Qborder_color, "border-color"); @@ -5700,13 +6159,12 @@ syms_of_frame (void) DEFSYM (Qhorizontal_scroll_bars, "horizontal-scroll-bars"); DEFSYM (Qicon_name, "icon-name"); DEFSYM (Qicon_type, "icon-type"); + DEFSYM (Qchild_frame_border_width, "child-frame-border-width"); DEFSYM (Qinternal_border_width, "internal-border-width"); DEFSYM (Qleft_fringe, "left-fringe"); DEFSYM (Qline_spacing, "line-spacing"); DEFSYM (Qmenu_bar_lines, "menu-bar-lines"); - DEFSYM (Qupdate_frame_menubar, "update-frame-menubar"); - DEFSYM (Qfree_frame_menubar_1, "free-frame-menubar-1"); - DEFSYM (Qfree_frame_menubar_2, "free-frame-menubar-2"); + DEFSYM (Qtab_bar_lines, "tab-bar-lines"); DEFSYM (Qmouse_color, "mouse-color"); DEFSYM (Qname, "name"); DEFSYM (Qright_divider_width, "right-divider-width"); @@ -5738,6 +6196,7 @@ syms_of_frame (void) DEFSYM (Qtop_only, "top-only"); DEFSYM (Qiconify_top_level, "iconify-top-level"); DEFSYM (Qmake_invisible, "make-invisible"); + DEFSYM (Quse_frame_synchronization, "use-frame-synchronization"); { int i; @@ -5747,7 +6206,7 @@ syms_of_frame (void) Lisp_Object v = (frame_parms[i].sym < 0 ? intern_c_string (frame_parms[i].name) : builtin_lisp_symbol (frame_parms[i].sym)); - Fput (v, Qx_frame_parameter, make_number (i)); + Fput (v, Qx_frame_parameter, make_fixnum (i)); } } @@ -5780,21 +6239,31 @@ is a reasonable practice. See also the variable `x-resource-name'. */); doc: /* The lower limit of the frame opacity (alpha transparency). The value should range from 0 (invisible) to 100 (completely opaque). You can also use a floating number between 0.0 and 1.0. */); - Vframe_alpha_lower_limit = make_number (20); + Vframe_alpha_lower_limit = make_fixnum (20); #endif DEFVAR_LISP ("default-frame-alist", Vdefault_frame_alist, - doc: /* Alist of default values for frame creation. + doc: /* Alist of default values of frame parameters for frame creation. These may be set in your init file, like this: (setq default-frame-alist \\='((width . 80) (height . 55) (menu-bar-lines . 1))) + These override values given in window system configuration data, - including X Windows' defaults database. +including X Windows' defaults database. + +Note that many display-related modes (like `scroll-bar-mode' or +`menu-bar-mode') alter `default-frame-alist', so if you set this +variable directly, you may be overriding other settings +unintentionally. Instead it's often better to use +`modify-all-frames-parameters' or push new elements to the front of +this alist. + For values specific to the first Emacs frame, see `initial-frame-alist'. + For window-system specific values, see `window-system-default-frame-alist'. + For values specific to the separate minibuffer frame, see - `minibuffer-frame-alist'. -The `menu-bar-lines' element of the list controls whether new frames - have menu bars; `menu-bar-mode' works by altering this element. +`minibuffer-frame-alist'. + Setting this variable does not affect existing frames, only new ones. */); Vdefault_frame_alist = Qnil; @@ -5814,7 +6283,7 @@ Setting this variable does not affect existing frames, only new ones. */); DEFVAR_BOOL ("scroll-bar-adjust-thumb-portion", scroll_bar_adjust_thumb_portion_p, - doc: /* Adjust thumb for overscrolling for Gtk+ and MOTIF. + doc: /* Adjust scroll bars for overscrolling for Gtk+, Motif and Haiku. Non-nil means adjust the thumb in the scroll bar so it can be dragged downwards even if the end of the buffer is shown (i.e. overscrolling). Set to nil if you want the thumb to be at the bottom when the end of the buffer @@ -5835,25 +6304,19 @@ which need to do mouse handling at the Lisp level. */); DEFVAR_LISP ("mouse-highlight", Vmouse_highlight, doc: /* If non-nil, clickable text is highlighted when mouse is over it. -If the value is an integer, highlighting is only shown after moving the +If the value is an integer, highlighting is shown only after moving the mouse, while keyboard input turns off the highlight even when the mouse is over the clickable text. However, the mouse shape still indicates when the mouse is over clickable text. */); Vmouse_highlight = Qt; DEFVAR_LISP ("make-pointer-invisible", Vmake_pointer_invisible, - doc: /* If non-nil, make pointer invisible while typing. -The pointer becomes visible again when the mouse is moved. */); - Vmake_pointer_invisible = Qt; + doc: /* If non-nil, make mouse pointer invisible while typing. +The pointer becomes visible again when the mouse is moved. - DEFVAR_LISP ("focus-in-hook", Vfocus_in_hook, - doc: /* Normal hook run when a frame gains input focus. -The frame gaining focus is selected at the time this hook is run. */); - Vfocus_in_hook = Qnil; - - DEFVAR_LISP ("focus-out-hook", Vfocus_out_hook, - doc: /* Normal hook run when all frames lost input focus. */); - Vfocus_out_hook = Qnil; +When using this, you might also want to disable highlighting of +clickable text. See `mouse-highlight'. */); + Vmake_pointer_invisible = Qt; DEFVAR_LISP ("move-frame-functions", Vmove_frame_functions, doc: /* Functions run after a frame was moved. @@ -5872,6 +6335,14 @@ recursively). */); Vdelete_frame_functions = Qnil; DEFSYM (Qdelete_frame_functions, "delete-frame-functions"); + DEFVAR_LISP ("after-delete-frame-functions", + Vafter_delete_frame_functions, + doc: /* Functions run after deleting a frame. +The functions are run with one arg, the frame that was deleted and +which is now dead. */); + Vafter_delete_frame_functions = Qnil; + DEFSYM (Qafter_delete_frame_functions, "after-delete-frame-functions"); + DEFVAR_LISP ("menu-bar-mode", Vmenu_bar_mode, doc: /* Non-nil if Menu-Bar mode is enabled. See the command `menu-bar-mode' for a description of this minor mode. @@ -5880,6 +6351,14 @@ either customize it (see the info node `Easy Customization') or call the function `menu-bar-mode'. */); Vmenu_bar_mode = Qt; + DEFVAR_LISP ("tab-bar-mode", Vtab_bar_mode, + doc: /* Non-nil if Tab-Bar mode is enabled. +See the command `tab-bar-mode' for a description of this minor mode. +Setting this variable directly does not take effect; +either customize it (see the info node `Easy Customization') +or call the function `tab-bar-mode'. */); + Vtab_bar_mode = Qnil; + DEFVAR_LISP ("tool-bar-mode", Vtool_bar_mode, doc: /* Non-nil if Tool-Bar mode is enabled. See the command `tool-bar-mode' for a description of this minor mode. @@ -5893,19 +6372,27 @@ or call the function `tool-bar-mode'. */); #endif DEFVAR_KBOARD ("default-minibuffer-frame", Vdefault_minibuffer_frame, - doc: /* Minibufferless frames use this frame's minibuffer. -Emacs cannot create minibufferless frames unless this is set to an -appropriate surrogate. - -Emacs consults this variable only when creating minibufferless -frames; once the frame is created, it sticks with its assigned -minibuffer, no matter what this variable is set to. This means that -this variable doesn't necessarily say anything meaningful about the -current set of frames, or where the minibuffer is currently being -displayed. + doc: /* Minibuffer-less frames by default use this frame's minibuffer. +Emacs consults this variable only when creating a minibuffer-less frame +and no explicit minibuffer window has been specified for that frame via +the `minibuffer' frame parameter. Once such a frame has been created, +setting this variable does not change that frame's previous association. This variable is local to the current terminal and cannot be buffer-local. */); + DEFVAR_LISP ("resize-mini-frames", resize_mini_frames, + doc: /* Non-nil means resize minibuffer-only frames automatically. +If this is nil, do not resize minibuffer-only frames automatically. + +If this is a function, call that function with the minibuffer-only +frame that shall be resized as sole argument. The buffer of the root +window of that frame is the buffer whose text will be eventually shown +in the minibuffer window. + +Any other non-nil value means to resize minibuffer-only frames by +calling `fit-mini-frame-to-buffer'. */); + resize_mini_frames = Qnil; + DEFVAR_LISP ("focus-follows-mouse", focus_follows_mouse, doc: /* Non-nil if window system changes focus when you move the mouse. You should set this variable to tell Emacs how your window manager @@ -5967,18 +6454,18 @@ a non-nil value in your init file. */); DEFVAR_LISP ("frame-inhibit-implied-resize", frame_inhibit_implied_resize, doc: /* Whether frames should be resized implicitly. -If this option is nil, setting font, menu bar, tool bar, internal +If this option is nil, setting font, menu bar, tool bar, tab bar, internal borders, fringes or scroll bars of a specific frame may resize the frame in order to preserve the number of columns or lines it displays. If this option is t, no such resizing is done. Note that the size of fullscreen and maximized frames, the height of fullheight frames and the width of fullwidth frames never change implicitly. -The value of this option can be also be a list of frame parameters. In -this case, resizing is inhibited when changing a parameter that appears -in that list. The parameters currently handled by this option include -`font', `font-backend', `internal-border-width', `menu-bar-lines' and -`tool-bar-lines'. +The value of this option can be also a list of frame parameters. In +this case, resizing is inhibited when changing a parameter that +appears in that list. The parameters currently handled by this option +include `font', `font-backend', `internal-border-width', +`menu-bar-lines', `tool-bar-lines' and `tab-bar-lines'. Changing any of the parameters `scroll-bar-width', `scroll-bar-height', `vertical-scroll-bars', `horizontal-scroll-bars', `left-fringe' and @@ -5989,21 +6476,22 @@ width by the width of one scroll bar provided this option is nil and keep it unchanged if this option is either t or a list containing `vertical-scroll-bars'. -The default value is \\='(tool-bar-lines) on Lucid, Motif and Windows -\(which means that adding/removing a tool bar does not change the frame -height), nil on all other window systems including GTK+ (which means -that changing any of the parameters listed above may change the size of -the frame), and t otherwise (which means the frame size never changes -implicitly when there's no window system support). +In GTK+ and NS that use the external tool bar, the default value is +\\='(tab-bar-lines) which means that adding/removing a tab bar does +not change the frame height. On all other types of GUI frames, the +default value is \\='(tab-bar-lines tool-bar-lines) which means that +adding/removing a tool bar or tab bar does not change the frame +height. Otherwise it's t which means the frame size never changes +implicitly when there's no window system support. Note that when a frame is not large enough to accommodate a change of any of the parameters listed above, Emacs may try to enlarge the frame even if this option is non-nil. */); #if defined (HAVE_WINDOW_SYSTEM) -#if defined (USE_LUCID) || defined (USE_MOTIF) || defined (HAVE_NTGUI) - frame_inhibit_implied_resize = list1 (Qtool_bar_lines); +#if defined (USE_GTK) || defined (HAVE_NS) + frame_inhibit_implied_resize = list1 (Qtab_bar_lines); #else - frame_inhibit_implied_resize = Qnil; + frame_inhibit_implied_resize = list2 (Qtab_bar_lines, Qtool_bar_lines); #endif #else frame_inhibit_implied_resize = Qt; @@ -6041,6 +6529,14 @@ This variable is effective only with the X toolkit (and there only when Gtk+ tooltips are not used) and on Windows. */); tooltip_reuse_hidden_frame = false; + DEFVAR_BOOL ("use-system-tooltips", use_system_tooltips, + doc: /* Use the toolkit to display tooltips. +This option is only meaningful when Emacs is built with GTK+ or Haiku +windowing support, and results in tooltips that look like those +displayed by other GTK+ or Haiku programs, but will not be able to +display text properties inside tooltip text. */); + use_system_tooltips = true; + DEFVAR_LISP ("iconify-child-frame", iconify_child_frame, doc: /* How to handle iconification of child frames. This variable tells Emacs how to proceed when it is asked to iconify a @@ -6056,16 +6552,23 @@ making the child frame unresponsive to user actions, the default is to iconify the top level frame instead. */); iconify_child_frame = Qiconify_top_level; - staticpro (&Vframe_list); + DEFVAR_LISP ("frame-internal-parameters", frame_internal_parameters, + doc: /* Frame parameters specific to every frame. */); +#ifdef HAVE_X_WINDOWS + frame_internal_parameters = list4 (Qname, Qparent_id, Qwindow_id, Qouter_window_id); +#else + frame_internal_parameters = list3 (Qname, Qparent_id, Qwindow_id); +#endif defsubr (&Sframep); defsubr (&Sframe_live_p); defsubr (&Swindow_system); defsubr (&Sframe_windows_min_size); defsubr (&Smake_terminal_frame); - defsubr (&Shandle_switch_frame); defsubr (&Sselect_frame); + defsubr (&Shandle_switch_frame); defsubr (&Sselected_frame); + defsubr (&Sold_selected_frame); defsubr (&Sframe_list); defsubr (&Sframe_parent); defsubr (&Sframe_ancestor_p); @@ -6108,6 +6611,7 @@ iconify the top level frame instead. */); defsubr (&Sscroll_bar_width); defsubr (&Sscroll_bar_height); defsubr (&Sfringe_width); + defsubr (&Sframe_child_frame_border_width); defsubr (&Sframe_internal_border_width); defsubr (&Sright_divider_width); defsubr (&Sbottom_divider_width); @@ -6118,6 +6622,10 @@ iconify the top level frame instead. */); defsubr (&Sframe_position); defsubr (&Sset_frame_position); defsubr (&Sframe_pointer_visible_p); + defsubr (&Sframe__set_was_invisible); + defsubr (&Sframe_window_state_change); + defsubr (&Sset_frame_window_state_change); + defsubr (&Sframe_scale_factor); #ifdef HAVE_WINDOW_SYSTEM defsubr (&Sx_get_resource); |