From fc83f3795174213a412920232c85377f2a30bb7f Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Fri, 5 Mar 2021 14:42:22 +0200 Subject: Fix initialization of 'while-no-input-ignore-events' * src/keyboard.c (syms_of_keyboard_for_pdumper): Don't reset 'while-no-input-ignore-events' after loading the dump file. (Bug#46940) --- src/keyboard.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/keyboard.c') diff --git a/src/keyboard.c b/src/keyboard.c index d142d4c1979..c3e4f5d36a8 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -12389,8 +12389,6 @@ syms_of_keyboard_for_pdumper (void) eassert (initial_kboard == NULL); initial_kboard = allocate_kboard (Qt); - Vwhile_no_input_ignore_events = Qnil; - inhibit_record_char = false; } -- cgit v1.2.3 From 82e3acc9cda5373d090d56b50a7b322d3ce9d8b1 Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Fri, 12 Mar 2021 14:33:41 -0500 Subject: * src/keyboard.c parse_solitary_modifier): Accept `click` modifier --- src/keyboard.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/keyboard.c') diff --git a/src/keyboard.c b/src/keyboard.c index e3fc6adf813..512fa279b38 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -6679,6 +6679,7 @@ parse_solitary_modifier (Lisp_Object symbol) case 'c': MULTI_LETTER_MOD (ctrl_modifier, "ctrl", 4); MULTI_LETTER_MOD (ctrl_modifier, "control", 7); + MULTI_LETTER_MOD (click_modifier, "click", 5); break; case 'H': -- cgit v1.2.3 From ce1b4acd71e962b6a72a779ee04cb5aeb6ceb6f2 Mon Sep 17 00:00:00 2001 From: Michael Albinus Date: Thu, 18 Mar 2021 12:43:35 +0100 Subject: Extend handled events in 'while-no-input-ignore-events' (Bug#47205) * etc/NEWS: Mention changes to 'while-no-input-ignore-events'. * src/keyboard.c (kbd_buffer_store_buffered_event): Handle also Qfile_notify and Qdbus_event as ignore_event. (Bug#47205) --- etc/NEWS | 14 ++++++++++---- src/keyboard.c | 6 ++++++ 2 files changed, 16 insertions(+), 4 deletions(-) (limited to 'src/keyboard.c') diff --git a/etc/NEWS b/etc/NEWS index 20407db0acd..d5cfed46fb8 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -532,7 +532,7 @@ It can be used to enable/disable the tab bar individually on each frame independently from the value of 'tab-bar-mode' and 'tab-bar-show'. --- -*** New option 'tab-bar-format' defines a list of tab bar items. +*** New user option 'tab-bar-format' defines a list of tab bar items. When it contains 'tab-bar-format-global' (possibly appended after 'tab-bar-format-align-right'), then after enabling 'display-time-mode' (or any other mode that uses 'global-mode-string') it displays time @@ -558,7 +558,8 @@ It also supports a negative argument. --- *** 'C-x t G' assigns a group name to the tab. 'tab-close-group' can close all tabs that belong to the selected group. -The option 'tab-bar-new-tab-group' defines the default group of a new tab. +The user option 'tab-bar-new-tab-group' defines the default group of a +new tab. --- *** New user option 'tab-bar-tab-name-format-function'. @@ -2257,8 +2258,8 @@ first). ** The 'M-o M-s' and 'M-o M-S' global bindings have been removed. Use 'M-x center-line' and 'M-x center-paragraph' instead. -** The 'M-o M-o' global binding have been removed. -Use 'M-x font-lock-fontify-block' instead, or the new `C-x x f' +** The 'M-o M-o' global binding has been removed. +Use 'M-x font-lock-fontify-block' instead, or the new 'C-x x f' command, which toggles fontification in the current buffer. ** In 'f90-mode', the backslash character ('\') no longer escapes. @@ -2825,6 +2826,11 @@ semantics of RFC 8259 instead of the earlier RFC 4627. In particular, these functions now accept top-level JSON values that are neither arrays nor objects. +--- +** 'while-no-input-ignore-events' accepts more special events. +The special events 'dbus-event' and 'file-notify' are now ignored in +'while-no-input' when added to this variable. + * Changes in Emacs 28.1 on Non-Free Operating Systems diff --git a/src/keyboard.c b/src/keyboard.c index 512fa279b38..266ebaa5fdf 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -3614,6 +3614,12 @@ kbd_buffer_store_buffered_event (union buffered_input_event *event, case ICONIFY_EVENT: ignore_event = Qiconify_frame; break; case DEICONIFY_EVENT: ignore_event = Qmake_frame_visible; break; case SELECTION_REQUEST_EVENT: ignore_event = Qselection_request; break; +#ifdef USE_FILE_NOTIFY + case FILE_NOTIFY_EVENT: ignore_event = Qfile_notify; break; +#endif +#ifdef HAVE_DBUS + case DBUS_EVENT: ignore_event = Qdbus_event; break; +#endif default: ignore_event = Qnil; break; } -- cgit v1.2.3 From 846989498b66f94739e78ca274c8d1176c137591 Mon Sep 17 00:00:00 2001 From: Alan Mackenzie Date: Thu, 22 Apr 2021 12:07:21 +0000 Subject: Fix unclean "can't happen" error handling in read_minibuf_unwind Also fix a bug where, with minibuffer-follows-selected-frame neither nil nor t, a minibuffer could appear in two frames at the same time. * src/window.c (Fset_window_configuration): Add a new &optional parameter DONT-SET-MINIWINDOW, which inhibits the minibuffer from being restored from the supplied window configuration. (restore_window_configuration): Enhance to match the above. * src/minibuf.c (read_minibuf): Enhance the argument list to the restore_window_configuration calls to match the above. In the main case, restoring the minibuffer is inhibited. (read_minibuf_unwind): Should the frame with the expired minibuffer not be found ("can't happen"), unwind the stacked data nevertheless, rather than just exiting. * src/keyboard.c (read_char_help_form_unwind): Amend a call of Fset_window_configuration. * doc/lispref/windows.texi (Window Configurations): Document the new form of set-window-configuration. * etc/NEWS (Lisp Changes in Emacs 28.1): Amend the entry for set-window-configuration. --- doc/lispref/windows.texi | 10 +++++++--- etc/NEWS | 8 +++++--- src/keyboard.c | 2 +- src/minibuf.c | 21 ++++++++++----------- src/window.c | 21 ++++++++++++++------- 5 files changed, 37 insertions(+), 25 deletions(-) (limited to 'src/keyboard.c') diff --git a/doc/lispref/windows.texi b/doc/lispref/windows.texi index c32d711f12a..82d2ce4757b 100644 --- a/doc/lispref/windows.texi +++ b/doc/lispref/windows.texi @@ -5877,7 +5877,7 @@ which window parameters (if any) are saved by this function. @xref{Window Parameters}. @end defun -@defun set-window-configuration configuration &optional dont-set-frame +@defun set-window-configuration configuration &optional dont-set-frame dont-set-miniwindow This function restores the configuration of windows and buffers as specified by @var{configuration}, for the frame that @var{configuration} was created for, regardless of whether that frame @@ -5885,8 +5885,12 @@ is selected or not. The argument @var{configuration} must be a value that was previously returned by @code{current-window-configuration} for that frame. Normally the function also selects the frame which is recorded in the configuration, but if @var{dont-set-frame} is -non-@code{nil}, it leaves selected the frame which was current at the -start of the function. +non-@code{nil}, it leaves selected the frame which was already +selected at the start of the function. + +Normally the function restores the saved minibuffer (if any), but if +@var{dont-set-miniwindow} is non-@code{nil}, the minibuffer current +at the start of the function (if any) remains in the mini-window. If the frame from which @var{configuration} was saved is dead, all this function does is to restore the value of the variable diff --git a/etc/NEWS b/etc/NEWS index 559ffd6d8f6..e7258f19b46 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -2674,9 +2674,11 @@ one to another in the init file. The same user option also controls whether the function 'read-answer' accepts short answers. +++ -** 'set-window-configuration' now takes an optional 'dont-set-frame' -parameter which, when non-nil, instructs the function not to select -the frame recorded in the configuration. +** 'set-window-configuration' now takes two optional parameters, +'dont-set-frame' and 'dont-set-miniwindow'. The first of these, when +non-nil, instructs the function not to select the frame recorded in +the configuration. The second prevents the current minibuffer being +replaced by the one stored in the configuration. +++ ** 'define-globalized-minor-mode' now takes a ':predicate' parameter. diff --git a/src/keyboard.c b/src/keyboard.c index 266ebaa5fdf..5db45ce8e57 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -2121,7 +2121,7 @@ read_char_help_form_unwind (void) Lisp_Object window_config = XCAR (help_form_saved_window_configs); help_form_saved_window_configs = XCDR (help_form_saved_window_configs); if (!NILP (window_config)) - Fset_window_configuration (window_config, Qnil); + Fset_window_configuration (window_config, Qnil, Qnil); } #define STOP_POLLING \ diff --git a/src/minibuf.c b/src/minibuf.c index 1a637c86ade..c4482d7f1ee 100644 --- a/src/minibuf.c +++ b/src/minibuf.c @@ -660,17 +660,14 @@ read_minibuf (Lisp_Object map, Lisp_Object initial, Lisp_Object prompt, record_unwind_protect_void (minibuffer_unwind); record_unwind_protect (restore_window_configuration, - Fcons (Qt, Fcurrent_window_configuration (Qnil))); + list3 (Fcurrent_window_configuration (Qnil), Qt, Qt)); /* If the minibuffer window is on a different frame, save that frame's configuration too. */ if (!EQ (mini_frame, selected_frame)) record_unwind_protect (restore_window_configuration, - Fcons (/* Arrange for the frame later to be - switched back to the calling - frame. */ - Qnil, - Fcurrent_window_configuration (mini_frame))); + list3 (Fcurrent_window_configuration (mini_frame), + Qnil, Qt)); /* If the minibuffer is on an iconified or invisible frame, make it visible now. */ @@ -1069,13 +1066,13 @@ read_minibuf_unwind (void) goto found; } } - return; /* expired minibuffer not found. Maybe we should output an - error, here. */ + exp_MB_frame = Qnil; /* "Can't happen." */ found: - if (!EQ (exp_MB_frame, saved_selected_frame)) + if (!EQ (exp_MB_frame, saved_selected_frame) + && !NILP (exp_MB_frame)) do_switch_frame (exp_MB_frame, 0, 0, Qt); /* This also sets - minibuff_window */ + minibuf_window */ /* To keep things predictable, in case it matters, let's be in the minibuffer when we reset the relevant variables. Don't depend on @@ -1185,7 +1182,8 @@ read_minibuf_unwind (void) } /* Restore the selected frame. */ - if (!EQ (exp_MB_frame, saved_selected_frame)) + if (!EQ (exp_MB_frame, saved_selected_frame) + && !NILP (exp_MB_frame)) do_switch_frame (saved_selected_frame, 0, 0, Qt); } @@ -1200,6 +1198,7 @@ minibuffer_unwind (void) Lisp_Object window; Lisp_Object entry; + if (NILP (exp_MB_frame)) return; /* "Can't happen." */ f = XFRAME (exp_MB_frame); window = f->minibuffer_window; w = XWINDOW (window); diff --git a/src/window.c b/src/window.c index a22fab24441..5134c3df63d 100644 --- a/src/window.c +++ b/src/window.c @@ -6881,19 +6881,22 @@ DEFUN ("window-configuration-frame", Fwindow_configuration_frame, Swindow_config } DEFUN ("set-window-configuration", Fset_window_configuration, - Sset_window_configuration, 1, 2, 0, + Sset_window_configuration, 1, 3, 0, doc: /* Set the configuration of windows and buffers as specified by CONFIGURATION. CONFIGURATION must be a value previously returned by `current-window-configuration' (which see). Normally, this function selects the frame of the CONFIGURATION, but if DONT-SET-FRAME is non-nil, it leaves selected the frame which was -current at the start of the function. +current at the start of the function. If DONT-SET-MINIWINDOW is non-nil, +the mini-window of the frame doesn't get set to the corresponding element +of CONFIGURATION. If CONFIGURATION was made from a frame that is now deleted, only frame-independent values can be restored. In this case, the return value is nil. Otherwise the value is t. */) - (Lisp_Object configuration, Lisp_Object dont_set_frame) + (Lisp_Object configuration, Lisp_Object dont_set_frame, + Lisp_Object dont_set_miniwindow) { register struct save_window_data *data; struct Lisp_Vector *saved_windows; @@ -7104,8 +7107,10 @@ the return value is nil. Otherwise the value is t. */) } } - if (BUFFERP (p->buffer) && BUFFER_LIVE_P (XBUFFER (p->buffer))) - /* If saved buffer is alive, install it. */ + if ((NILP (dont_set_miniwindow) || !MINI_WINDOW_P (w)) + && BUFFERP (p->buffer) && BUFFER_LIVE_P (XBUFFER (p->buffer))) + /* If saved buffer is alive, install it, unless it's a + minibuffer we explicitly prohibit. */ { wset_buffer (w, p->buffer); w->start_at_line_beg = !NILP (p->start_at_line_beg); @@ -7258,9 +7263,11 @@ void restore_window_configuration (Lisp_Object configuration) { if (CONSP (configuration)) - Fset_window_configuration (XCDR (configuration), XCAR (configuration)); + Fset_window_configuration (XCAR (configuration), + XCAR (XCDR (configuration)), + XCAR (XCDR (XCDR (configuration)))); else - Fset_window_configuration (configuration, Qnil); + Fset_window_configuration (configuration, Qnil, Qnil); } -- cgit v1.2.3 From e1f0da91abf1fbe093d55cda324ce1fe20fe3f12 Mon Sep 17 00:00:00 2001 From: Stefan Kangas Date: Sun, 25 Apr 2021 11:49:37 +0200 Subject: * src/keyboard.c (Flossage_size): Improve prompt. --- src/keyboard.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/keyboard.c') diff --git a/src/keyboard.c b/src/keyboard.c index 5db45ce8e57..e9236fee1aa 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -10379,7 +10379,7 @@ update_recent_keys (int new_size, int kept_keys) } DEFUN ("lossage-size", Flossage_size, Slossage_size, 0, 1, - "(list (read-number \"new-size: \" (lossage-size)))", + "(list (read-number \"Set maximum keystrokes to: \" (lossage-size)))", doc: /* Return or set the maximum number of keystrokes to save. If called with a non-nil ARG, set the limit to ARG and return it. Otherwise, return the current limit. -- cgit v1.2.3 From a190b4cfd8b6f42a91678ac7292e1cceccd168e7 Mon Sep 17 00:00:00 2001 From: Martin Rudalics Date: Tue, 27 Apr 2021 09:53:42 +0200 Subject: Major rewrite of adjust_frame_size Have adjust_frame_size pass native frame sizes to backends instead of text sizes. Expand frame size history management. Drop PIXELWISE argument from change_frame_size and convert native to text sizes only when calling adjust_frame_size. Use convention in arguments that -1 instead of 0 means that no size change is required. When adjusting frame sizes pick up delayed size changes (Bug#46827). * lisp/frame.el (frame-notice-user-settings, make-frame): Don't set frame size history. (frame--size-history): Rewrite doc-string. Handle new formats of `frame-size-history' entries. * src/dispextern.h (delayed_size_change): Extern it. (change_frame_size): Drop last argument from extern. * src/dispnew.c (delayed_size_change): Make it global. (handle_window_change_signal): Reformat. Drop last argument from change_frame_size call. (do_pending_window_change, init_display_interactive): Drop last argument from change_frame_size call. (change_frame_size_1): NEW_WIDTH and NEW_HEIGHT now specify native sizes. Drop last argument PIXELWISE. Queue a change when it either differs from F's current pixel sizes or F's previously queued sizes. Inject frame_size_history_extra call when queuing. Adopt convention that for queued sizes -1 means that no size change is required. Convert from native to text sizes when calling adjust_frame_size. (change_frame_size): Drop last argument PIXELWISE and drop it also in change_frame_size_1 calls. * src/frame.c (frame_size_history_add): Remove. (frame_inhibit_resize): Remove call to frame_size_history_add. (set_menu_bar_lines, set_tab_bar_lines): Simplify. Drop last argument from change_frame_size call. (frame_windows_min_size): No more static. (keep_ratio): Minor rewrite using macros. (frame_size_history_adjust, frame_size_history_plain) (frame_size_history_extra): New functions. (adjust_frame_size): Major rewrite. Adopt new convention that negative values for new sizes mean no change. Pick up delayed size changes from F's new_width and new_height slots (Bug#46827). Call set_window_size_hook with native instead of text sizes. Do not sanitize window sizes any more. Call frame_size_history_adjust instead of frame_size_history_add. Always set F's resized_p slot to true. (make_frame): Initialize new_width and new_height slots to -1. Simplify setup of initial sizes and an adjust_frame_size call. (Fframe_parameters): Drop processing F's new_pixelwise slot. (check_frame_pixels): Reorder to make declarations appear first. (Fset_frame_height, Fset_frame_width, Fset_frame_size): Pass explicit width and height values to adjust_frame_size instead of -1. (gui_set_frame_parameters): Minor rewrite making sure that explicit sizes and the corresponding parameter are passed to adjust_frame_size. Remove frame_size_history_add call. (gui_figure_window_size): Drop last two arguments. Simplify assignment of initial size. Set new_height and new_width slots to -1. Use adjust_frame_size to set sizes instead of returning them to caller. (syms_of_frame): Drop symbols used by frame size history; these are now built on-the-fly. Also drop some menu bar related symbols in favor of Qmenu_bar_lines. * src/frame.h (struct frame): Remove new_pixelwise. (SET_FRAME_COLS, SET_FRAME_LINES, SET_FRAME_WIDTH) (SET_FRAME_HEIGHT): Remove macros. (frame_size_history_add): Remove externs. (frame_windows_min_size, frame_size_history_plain) (frame_size_history_extra): Add externs. (FRAME_WINDOWS_WIDTH, FRAME_WINDOWS_HEIGHT): Rename to FRAME_INNER_WIDTH and FRAME_INNER_HEIGHT. (gui_figure_window_size): Drop last two arguments from extern. * src/gtkutil.c (xg_frame_resized): Rename arguments to WIDTH and HEIGHT. Consult delayed_size_change to handle case where WIDTH and HEIGHT do not match F's new_width and new_height values. Call change_frame_size with native sizes and without PIXELWISE argument. Instead of frame_size_history_add call frame_size_history_extra. (xg_frame_set_char_size): WIDTH and HEIGHT are native sizes now; fix adjust_frame_size call accordingly. Instead of frame_size_history_add call frame_size_history_extra. (style_changed_cb): Call xg_frame_set_char_size with native instead of text sizes. (tb_size_cb): Remove frame_size_history_add call. Call adjust_frame_size with INHIBIT 5. (free_frame_tool_bar, xg_change_toolbar_position): Remove frame_size_history_add call. (update_frame_tool_bar): Call adjust_frame_size with INHIBIT 2 and let it handle frame_inhibit_implied_resize and fullheight/-width. Remove frame_size_history_add call. * src/keyboard.c (Fsuspend_emacs): Call change_frame_size with native sizes. * src/nsfns.m (ns_set_tool_bar_lines): Call adjust_frame_size with INHIBIT 2 and let it handle frame_inhibit_implied_resize and fullheight/-width. Remove frame_size_history_add call. (Fx_create_frame): Drop two last arguments in gui_figure_window_size call. Do not SET_FRAME_WIDTH and SET_FRAME_HEIGHT, the adjust_frame_size in gui_figure_window_size did that already. * src/nsterm.m (ns_set_window_size): Drop PIXELWISE argument and its processing; WIDTH and HEIGHT represent native pixel sizes now. Call change_frame_size with native sizes. Remove call to frame_size_history_add. ([EmacsView viewDidResize:]): Call change_frame_size with native sizes. * src/term.c (Fresume_tty): Call change_frame_size with native sizes. * src/termhooks.h (*set_window_size_hook): Drop last argument PIXELWISE. * src/w32fns.c (w32_change_tab_bar_height) (w32_change_tool_bar_height): Fix handling of these in the initial phase before they have been resized at least once. (Fx_create_frame, w32_create_tip_frame): Drop two last arguments in gui_figure_window_size call. Do not SET_FRAME_WIDTH and SET_FRAME_HEIGHT (or SET_FRAME_COLS and SET_FRAME_LINES), the adjust_frame_size in gui_figure_window_size did that already. * src/w32inevt.c (resize_event, maybe_generate_resize_event): Pass native sizes to change_frame_size. * src/w32term.c (w32_read_socket): When WM_WINDOWPOSCHANGED pass native sizes to change_frame_size. (w32_new_font): Recalculate FRAME_TAB_BAR_HEIGHT. Simplify code. (w32fullscreen_hook): Call change_frame_size with native sizes. (w32_set_window_size): Drop argument PIXELWISE and its processing; WIDTH and HEIGHT are native sizes now. Remove frame_size_history_add calls. Pass native sizes to change_frame_size. * src/widget.c (set_frame_size): Set width and height of widget directly. Call frame_size_history_plain instead of frame_size_history_add. (update_from_various_frame_slots): Call frame_size_history_extra. (EmacsFrameRealize): Call frame_size_history_plain. (EmacsFrameResize): Call change_frame_size with native sizes. Call frame_size_history_extra instead of frame_size_history_add. (EmacsFrameSetCharSize): Call frame_size_history_extra. Drop PIXELWISE argument in x_set_window_size call and specify pixels. (pixel_to_text_size): Remove function. * src/xdisp.c (resize_mini_window): Replace FRAME_WINDOWS_HEIGHT with FRAME_INNER_HEIGHT. (redisplay_tab_bar): Don't set tab_bar_redisplayed when we did not redisplay it. (redisplay_tool_bar): Don't call it for external tool bar. Don't set tool_bar_redisplayed when we did not redisplay it. (redisplay_window): When the tool bar is external call update_frame_tool_bar directly. * src/xfns.c (x_set_menu_bar_lines): Call adjust_frame_size only if number of menu bar lines changed and fix 6th argument. (x_change_tab_bar_height, x_change_tool_bar_height): Fix handling of these in the initial phase before they have been resized at least once. (Fx_create_frame, x_create_tip_frame): Drop two last arguments in gui_figure_window_size call. Do not SET_FRAME_WIDTH and SET_FRAME_HEIGHT (or SET_FRAME_COLS and SET_FRAME_LINES), the adjust_frame_size in gui_figure_window_size did that already. * src/xmenu.c (update_frame_menubar): Fix 6th arg of adjust_frame_size call. (free_frame_menubar): For Motif frames fix fullscreen and `frame-inhibit-implied-resize' handling. Fix 6th arg of adjust_frame_size calls. * src/xterm.c (x_net_wm_state): Remove call to frame_size_history_add. (handle_one_xevent): For PropertyNotify and UnmapNotify events add frame_size_history_plain calls. For MapNotify and ConfigureNotify events add a frame_size_history_extra call. For ConfigureNotify events also handle delayed size changes and call change_frame_size with native sizes. (x_new_font): Recalculate FRAME_TAB_BAR_HEIGHT. Simplify code. (x_handle_net_wm_state): Remove frame_size_history_add call. (x_check_fullscreen): Remove frame_size_history_add call. Call change_frame_size with native height. (x_set_window_size_1): WIDTH and HEIGHT are now native. Remove some frame_size_history_add calls and add frame_size_history_extra calls instead. If the frame is not visible call adjust_frame_size directly instead of calling change_frame_size. (x_set_window_size): Drop PIXELWISE argument. WIDTH and HEIGHT represent native sizes now. (x_make_frame_visible, x_make_frame_invisible): Call frame_size_history_plain. * src/xterm.h (x_set_window_size): Drop last argument from extern declaration. --- lisp/frame.el | 121 ++++++--- src/dispextern.h | 4 +- src/dispnew.c | 120 +++++---- src/frame.c | 732 ++++++++++++++++++++++++++++++------------------------- src/frame.h | 213 ++++++---------- src/gtkutil.c | 158 +++++------- src/keyboard.c | 5 +- src/nsfns.m | 26 +- src/nsterm.m | 41 +--- src/term.c | 4 +- src/termhooks.h | 2 +- src/w32fns.c | 100 +++----- src/w32inevt.c | 12 +- src/w32term.c | 156 ++++-------- src/widget.c | 75 +++--- src/xdisp.c | 29 +-- src/xfns.c | 135 ++++------ src/xmenu.c | 32 ++- src/xterm.c | 260 ++++++++------------ src/xterm.h | 2 +- 20 files changed, 1000 insertions(+), 1227 deletions(-) (limited to 'src/keyboard.c') diff --git a/lisp/frame.el b/lisp/frame.el index bca160175a5..aff1d479eca 100644 --- a/lisp/frame.el +++ b/lisp/frame.el @@ -615,15 +615,6 @@ there (in decreasing order of priority)." (face-set-after-frame-default frame-initial-frame) (setq newparms (delq new-bg newparms))) - (when (numberp (car frame-size-history)) - (setq frame-size-history - (cons (1- (car frame-size-history)) - (cons - (list frame-initial-frame - "FRAME-NOTICE-USER" - nil newparms) - (cdr frame-size-history))))) - (modify-frame-parameters frame-initial-frame newparms))))) ;; Restore the original buffer. @@ -926,12 +917,6 @@ the new frame according to its own rules." (let ((val (frame-parameter oldframe param))) (when val (set-frame-parameter frame param val))))) - (when (numberp (car frame-size-history)) - (setq frame-size-history - (cons (1- (car frame-size-history)) - (cons (list frame "MAKE-FRAME") - (cdr frame-size-history))))) - ;; We can run `window-configuration-change-hook' for this frame now. (frame-after-make-frame frame t) (run-hook-with-args 'after-make-frame-functions frame) @@ -1695,26 +1680,104 @@ and width values are in pixels. (defun frame--size-history (&optional frame) "Print history of resize operations for FRAME. -Print prettified version of `frame-size-history' into a buffer -called *frame-size-history*. Optional argument FRAME denotes the -frame whose history will be printed. FRAME defaults to the -selected frame." +This function dumps a prettified version of `frame-size-history' +into a buffer called *frame-size-history*. The optional argument +FRAME denotes the frame whose history will be dumped; it defaults +to the selected frame. + +Storing information about resize operations is off by default. +If you set the variable `frame-size-history' like this + +(setq frame-size-history '(100)) + +then Emacs will save information about the next 100 significant +operations affecting any frame's size in that variable. This +function prints the entries for FRAME stored in that variable in +a more legible way. + +All lines start with an indication of the requested action. An +entry like `menu-bar-lines' or `scroll-bar-width' indicates that +a change of the corresponding frame parameter or Lisp variable +was requested. An entry like gui_figure_window_size indicates +that that C function was executed, an entry like ConfigureNotify +indicates that that event was received. + +In long entries, a number in parentheses displays the INHIBIT +parameter passed to the C function adjust_frame_size. Such +entries may also display changes of frame rectangles in a form +like R=n1xn2~>n3xn4 where R denotes the rectangle type (TS for +text, NS for native and IS for inner frame rectangle sizes, all +in pixels, TC for text rectangle sizes in frame columns and +lines), n1 and n2 denote the old width and height and n3 and n4 +the new width and height in the according units. MS stands for +the minimum inner frame size in pixels, IH and IV, if present, +indicate that resizing horizontally and/or vertically was +inhibited (either by `frame-inhibit-implied-resize' or because of +the frame's fullscreen state). + +Shorter entries represent C functions that process width and +height changes of the native rectangle where PS stands for the +frame's present pixel width and height, XS for a requested pixel +width and height and DS for some earlier requested but so far +delayed pixel width and height. + +Very short entries represent calls of C functions that do not +directly ask for size changes but may indirectly affect the size +of frames like calls to map a frame or change its visibility." (let ((history (reverse frame-size-history)) - entry) + entry item) (setq frame (window-normalize-frame frame)) (with-current-buffer (get-buffer-create "*frame-size-history*") (erase-buffer) (insert (format "Frame size history of %s\n" frame)) (while (consp (setq entry (pop history))) - (when (eq (car entry) frame) - (pop entry) - (insert (format "%s" (pop entry))) - (move-to-column 24 t) - (while entry - (insert (format " %s" (pop entry)))) - (insert "\n"))) - (unless frame-size-history - (insert "Frame size history is nil.\n"))))) + (setq item (car entry)) + (cond + ((not (consp item)) + ;; An item added quickly for debugging purposes. + (insert (format "%s\n" entry))) + ((and (eq (nth 0 item) frame) (= (nth 1 item) 1)) + ;; Length 1 is a "plain event". + (insert (format "%s\n" (nth 2 item)))) + ((and (eq (nth 0 item) frame) (= (nth 1 item) 2)) + ;; Length 2 is an "extra" item. + (insert (format "%s" (nth 2 item))) + (setq item (nth 0 (cdr entry))) + (insert (format ", PS=%sx%s" (nth 0 item) (nth 1 item))) + (when (or (>= (nth 2 item) 0) (>= (nth 3 item) 0)) + (insert (format ", XS=%sx%s" (nth 2 item) (nth 3 item)))) + (setq item (nth 1 (cdr entry))) + (when (or (>= (nth 0 item) 0) (>= (nth 1 item) 0)) + (insert (format ", DS=%sx%s" (nth 0 item) (nth 1 item)))) + (insert "\n")) + ((and (eq (nth 0 item) frame) (= (nth 1 item) 5)) + ;; Length 5 is an `adjust-frame-size' item. + (insert (format "%s (%s)" (nth 3 item) (nth 2 item))) + (setq item (nth 0 (cdr entry))) + (unless (and (= (nth 0 item) (nth 2 item)) + (= (nth 1 item) (nth 3 item))) + (insert (format ", TS=%sx%s~>%sx%s" + (nth 0 item) (nth 1 item) (nth 2 item) (nth 3 item)))) + (setq item (nth 1 (cdr entry))) + (unless (and (= (nth 0 item) (nth 2 item)) + (= (nth 1 item) (nth 3 item))) + (insert (format ", TC=%sx%s~>%sx%s" + (nth 0 item) (nth 1 item) (nth 2 item) (nth 3 item)))) + (setq item (nth 2 (cdr entry))) + (unless (and (= (nth 0 item) (nth 2 item)) + (= (nth 1 item) (nth 3 item))) + (insert (format ", NS=%sx%s~>%sx%s" + (nth 0 item) (nth 1 item) (nth 2 item) (nth 3 item)))) + (setq item (nth 3 (cdr entry))) + (unless (and (= (nth 0 item) (nth 2 item)) + (= (nth 1 item) (nth 3 item))) + (insert (format ", IS=%sx%s~>%sx%s" + (nth 0 item) (nth 1 item) (nth 2 item) (nth 3 item)))) + (setq item (nth 4 (cdr entry))) + (insert (format ", MS=%sx%s" (nth 0 item) (nth 1 item))) + (when (nth 2 item) (insert " IH")) + (when (nth 3 item) (insert " IV")) + (insert "\n"))))))) (declare-function x-frame-edges "xfns.c" (&optional frame type)) (declare-function w32-frame-edges "w32fns.c" (&optional frame type)) diff --git a/src/dispextern.h b/src/dispextern.h index a2ebd04f235..213032d4de8 100644 --- a/src/dispextern.h +++ b/src/dispextern.h @@ -1262,7 +1262,7 @@ extern struct glyph space_glyph; /* True means last display completed. False means it was preempted. */ extern bool display_completed; - +extern bool delayed_size_change; /************************************************************************ @@ -3641,7 +3641,7 @@ extern void gui_update_window_begin (struct window *); extern void gui_update_window_end (struct window *, bool, bool); #endif void do_pending_window_change (bool); -void change_frame_size (struct frame *, int, int, bool, bool, bool, bool); +void change_frame_size (struct frame *, int, int, bool, bool, bool); void init_display (void); void syms_of_display (void); extern void spec_glyph_lookup_face (struct window *, GLYPH *); diff --git a/src/dispnew.c b/src/dispnew.c index f613f7b6568..b3f7be67e0f 100644 --- a/src/dispnew.c +++ b/src/dispnew.c @@ -102,7 +102,7 @@ bool display_completed; /* True means SIGWINCH happened when not safe. */ -static bool delayed_size_change; +bool delayed_size_change; /* A glyph for a space. */ @@ -5770,32 +5770,34 @@ handle_window_change_signal (int sig) termcap-controlled terminal, but we can't decide which. Therefore, we resize the frames corresponding to each tty. */ - for (tty = tty_list; tty; tty = tty->next) { + for (tty = tty_list; tty; tty = tty->next) + { + if (! tty->term_initted) + continue; - if (! tty->term_initted) - continue; + /* Suspended tty frames have tty->input == NULL avoid trying to + use it. */ + if (!tty->input) + continue; - /* Suspended tty frames have tty->input == NULL avoid trying to - use it. */ - if (!tty->input) - continue; + get_tty_size (fileno (tty->input), &width, &height); - get_tty_size (fileno (tty->input), &width, &height); + if (width > 5 && height > 2) + { + Lisp_Object tail, frame; - if (width > 5 && height > 2) { - Lisp_Object tail, frame; + FOR_EACH_FRAME (tail, frame) + { + struct frame *f = XFRAME (frame); - FOR_EACH_FRAME (tail, frame) - if (FRAME_TERMCAP_P (XFRAME (frame)) && FRAME_TTY (XFRAME (frame)) == tty) - /* Record the new sizes, but don't reallocate the data - structures now. Let that be done later outside of the - signal handler. */ - change_frame_size (XFRAME (frame), width, - height - FRAME_MENU_BAR_LINES (XFRAME (frame)) - - FRAME_TAB_BAR_LINES (XFRAME (frame)), - 0, 1, 0, 0); + if (FRAME_TERMCAP_P (f) && FRAME_TTY (f) == tty) + /* Record the new sizes, but don't reallocate the data + structures now. Let that be done later outside of the + signal handler. */ + change_frame_size (f, width, height, false, true, false); + } + } } - } } static void @@ -5821,15 +5823,17 @@ do_pending_window_change (bool safe) { Lisp_Object tail, frame; - delayed_size_change = 0; + delayed_size_change = false; FOR_EACH_FRAME (tail, frame) { struct frame *f = XFRAME (frame); - if (f->new_height != 0 || f->new_width != 0) + /* Negative new_width or new_height values mean no change is + required (a native size can never drop below zero). */ + if (f->new_height >= 0 || f->new_width >= 0) change_frame_size (f, f->new_width, f->new_height, - 0, 0, safe, f->new_pixelwise); + false, false, safe); } } } @@ -5837,47 +5841,43 @@ do_pending_window_change (bool safe) static void change_frame_size_1 (struct frame *f, int new_width, int new_height, - bool pretend, bool delay, bool safe, bool pixelwise) + bool pretend, bool delay, bool safe) { - /* If we can't deal with the change now, queue it for later. */ if (delay || (redisplaying_p && !safe)) { + if (CONSP (frame_size_history) + && ((new_width != f->new_width + || new_height != f->new_height + || new_width != FRAME_PIXEL_WIDTH (f) + || new_height != FRAME_PIXEL_HEIGHT (f)))) + frame_size_history_extra + (f, build_string ("change_frame_size_1, delayed"), + FRAME_PIXEL_WIDTH (f), FRAME_PIXEL_HEIGHT (f), + new_width, new_height, f->new_width, f->new_height); + + /* We can't deal with the change now, queue it for later. */ f->new_width = new_width; f->new_height = new_height; - f->new_pixelwise = pixelwise; - delayed_size_change = 1; + delayed_size_change = true; } else { - /* This size-change overrides any pending one for this frame. */ - f->new_height = 0; - f->new_width = 0; - f->new_pixelwise = 0; - - /* If an argument is zero, set it to the current value. */ - if (pixelwise) - { - new_width = (new_width <= 0) ? FRAME_TEXT_WIDTH (f) : new_width; - new_height = (new_height <= 0) ? FRAME_TEXT_HEIGHT (f) : new_height; - } - else - { - new_width = (((new_width <= 0) ? FRAME_COLS (f) : new_width) - * FRAME_COLUMN_WIDTH (f)); - new_height = (((new_height <= 0) ? FRAME_LINES (f) : new_height) - * FRAME_LINE_HEIGHT (f)); - } - - /* Adjust frame size but make sure set_window_size_hook does not - get called. */ - adjust_frame_size (f, new_width, new_height, 5, pretend, - Qchange_frame_size); + /* Storing -1 in the new_width/new_height slots means that no size + change is pending. Native sizes are always non-negative. */ + f->new_height = -1; + f->new_width = -1; + /* adjust_frame_size wants its arguments in terms of text_width + and text_height, so convert them here. For pathologically + small frames, the resulting values may be negative though. */ + adjust_frame_size (f, FRAME_PIXEL_TO_TEXT_WIDTH (f, new_width), + FRAME_PIXEL_TO_TEXT_HEIGHT (f, new_height), 5, + pretend, Qchange_frame_size); } } -/* Change text height/width of frame F. Values may be given as zero to - indicate that no change is needed. +/* Change native height/width of frame F to NEW_WIDTH/NEW_HEIGHT pixels. + Values may be given as -1 to indicate that no change is needed. If DELAY, assume we're being called from a signal handler, and queue the change for later - perhaps the next redisplay. Since this tries @@ -5887,7 +5887,7 @@ change_frame_size_1 (struct frame *f, int new_width, int new_height, change frame sizes while a redisplay is in progress. */ void change_frame_size (struct frame *f, int new_width, int new_height, - bool pretend, bool delay, bool safe, bool pixelwise) + bool pretend, bool delay, bool safe) { Lisp_Object tail, frame; @@ -5897,13 +5897,12 @@ change_frame_size (struct frame *f, int new_width, int new_height, size affects all frames. Termcap now supports multiple ttys. */ FOR_EACH_FRAME (tail, frame) - if (! FRAME_WINDOW_P (XFRAME (frame))) + if (!FRAME_WINDOW_P (XFRAME (frame))) change_frame_size_1 (XFRAME (frame), new_width, new_height, - pretend, delay, safe, pixelwise); + pretend, delay, safe); } else - change_frame_size_1 (f, new_width, new_height, pretend, delay, safe, - pixelwise); + change_frame_size_1 (f, new_width, new_height, pretend, delay, safe); } /*********************************************************************** @@ -6492,9 +6491,8 @@ init_display_interactive (void) t->display_info.tty->top_frame = selected_frame; change_frame_size (XFRAME (selected_frame), FrameCols (t->display_info.tty), - FrameRows (t->display_info.tty) - - FRAME_MENU_BAR_LINES (f) - - FRAME_TAB_BAR_LINES (f), 0, 0, 1, 0); + FrameRows (t->display_info.tty), + false, false, true); /* Delete the initial terminal. */ if (--initial_terminal->reference_count == 0 diff --git a/src/frame.c b/src/frame.c index 097cd555c64..4129a70aa5f 100644 --- a/src/frame.c +++ b/src/frame.c @@ -150,29 +150,6 @@ get_frame_param (struct frame *frame, Lisp_Object prop) } -void -frame_size_history_add (struct frame *f, Lisp_Object fun_symbol, - int width, int height, Lisp_Object rest) -{ - 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 (list4 - (frame, fun_symbol, - ((width > 0) - ? list4i (FRAME_TEXT_WIDTH (f), FRAME_TEXT_HEIGHT (f), - width, height) - : Qnil), - rest), - XCDR (frame_size_history))); -} - - /* Return 1 if `frame-inhibit-implied-resize' is non-nil or fullscreen state of frame F would be affected by a vertical (horizontal if HORIZONTAL is true) resize. PARAMETER is the symbol of the frame @@ -193,78 +170,54 @@ frame_inhibit_resize (struct frame *f, bool horizontal, Lisp_Object parameter) || 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 (TYPE_RANGED_FIXNUMP (int, value)) - nlines = XFIXNUM (value); - else - nlines = 0; - - if (nlines != olines) + 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_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); } } + +/** Set tab bar lines for a TTY frame. */ static void set_tab_bar_lines (struct frame *f, Lisp_Object value, Lisp_Object oldval) { - int nlines; 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)) - return; - - if (TYPE_RANGED_FIXNUMP (int, value)) - nlines = XFIXNUM (value); - else - nlines = 0; - - if (nlines != olines) + if (!FRAME_MINIBUF_ONLY_P (f) && nlines != olines) { windows_or_buffers_changed = 14; - FRAME_TAB_BAR_LINES (f) = nlines; - FRAME_TAB_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: @@ -366,14 +319,15 @@ 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. For TTY frames, * additionally limit the minimum frame height to a value large enough - * to support the menu bar, the mode line, and the echo area. + * to support menu bar, tab bar, mode line and echo area. */ -static int +int frame_windows_min_size (Lisp_Object frame, Lisp_Object horizontal, Lisp_Object ignore, Lisp_Object pixelwise) { @@ -405,6 +359,7 @@ frame_windows_min_size (Lisp_Object frame, Lisp_Object horizontal, else 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)) @@ -413,6 +368,7 @@ frame_windows_min_size (Lisp_Object frame, Lisp_Object horizontal, + 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; } @@ -474,9 +430,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; @@ -496,14 +453,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; @@ -523,60 +481,143 @@ 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 set_window_size_hook), 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 argument INHIBIT can assume the following values: + * 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 controls whether set_window_size_hook may be + * called and can assume the following values: * * 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 set_window_size_hook 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 set_window_size_hook 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). + * 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 set_window_size_hook if window minimum sizes must be - * preserved or frame_inhibit_resize allows it. - * gui_set_left_fringe, gui_set_scroll_bar_width, gui_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 set_window_size_hook 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 set_window_size_hook. change_frame_size uses * this. @@ -588,146 +629,172 @@ keep_ratio (struct frame *f, struct frame *p, int old_width, int old_height, * 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 - set_window_size_hook 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_fixnum (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_set_window_size && ((!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; + new_native_width = old_native_width; else if (inhibit_vertical) - new_text_height = old_text_height; + new_native_height = old_native_height; + + if (inhibit == 2 && 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. Otherwsie, 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. */ + { + /* But 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. */ +#ifdef USE_MOTIF + if (!EQ (parameter, Qmenu_bar_lines)) +#endif + { + new_native_width = f->new_width; + new_native_height = f->new_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)); + 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 (FRAME_TERMINAL (f)->set_window_size_hook) FRAME_TERMINAL (f)->set_window_size_hook - (f, 0, new_text_width, new_text_height, 1); + (f, 0, new_native_width, new_native_height); f->resized_p = true; return; } -#endif + + 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 (); @@ -736,69 +803,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, true); + 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) if (WINDOWP (f->tab_bar_window)) { - XWINDOW (f->tab_bar_window)->pixel_width = new_windows_width; + XWINDOW (f->tab_bar_window)->pixel_width = new_inner_width; XWINDOW (f->tab_bar_window)->total_cols - = new_windows_width / unit_width; + = 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, false); + 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, - list4i (old_pixel_width, old_pixel_height, - new_pixel_width, 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)); @@ -812,18 +877,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 (); @@ -834,8 +899,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 } @@ -884,6 +949,8 @@ make_frame (bool mini_p) 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; @@ -932,17 +999,14 @@ make_frame (bool mini_p) wset_frame (rw, frame); - /* 80/25 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, 80); - SET_FRAME_LINES (f, 25); - 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 = FRAME_COLS (f); - rw->pixel_width = rw->total_cols * FRAME_COLUMN_WIDTH (f); rw->total_lines = FRAME_LINES (f) - (mini_p ? 1 : 0); rw->pixel_height = rw->total_lines * FRAME_LINE_HEIGHT (f); @@ -1316,8 +1380,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) - - FRAME_TAB_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); } @@ -3220,21 +3284,23 @@ 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. */ + height = (f->new_height >= 0 + ? f->new_height / FRAME_LINE_HEIGHT (f) : FRAME_LINES (f)); store_in_alist (&alist, Qheight, make_fixnum (height)); - width = (f->new_width - ? (f->new_pixelwise - ? (f->new_width / FRAME_COLUMN_WIDTH (f)) - : f->new_width) - : FRAME_COLS (f)); + width = (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, 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); @@ -3247,6 +3313,7 @@ If FRAME is omitted or nil, return information on the currently selected frame. { /* 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)); @@ -3593,15 +3660,18 @@ DEFUN ("frame-bottom-divider-width", Fbottom_divider_width, Sbottom_divider_widt 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; - intmax_t sz; - int pixel_size; /* size * item_size */ - if (! integer_to_intmax (size, &sz) + + 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; } @@ -3624,9 +3694,13 @@ 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 = check_frame_pixels (height, pixelwise, - FRAME_LINE_HEIGHT (f)); - adjust_frame_size (f, -1, pixel_height, 1, !NILP (pretend), Qheight); + int text_height + = check_frame_pixels (height, pixelwise, FRAME_LINE_HEIGHT (f)); + + /* 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; } @@ -3649,9 +3723,13 @@ 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_frame_pixels (width, pixelwise, - FRAME_COLUMN_WIDTH (f)); - adjust_frame_size (f, pixel_width, -1, 1, !NILP (pretend), Qwidth); + int text_width + = check_frame_pixels (width, pixelwise, FRAME_COLUMN_WIDTH (f)); + + /* 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; } @@ -3667,11 +3745,14 @@ 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 = check_frame_pixels (width, pixelwise, - FRAME_COLUMN_WIDTH (f)); - int pixel_height = check_frame_pixels (height, pixelwise, - FRAME_LINE_HEIGHT (f)); - adjust_frame_size (f, pixel_width, pixel_height, 1, 0, Qsize); + int text_width + = check_frame_pixels (width, pixelwise, FRAME_COLUMN_WIDTH (f)); + int text_height + = check_frame_pixels (height, pixelwise, FRAME_LINE_HEIGHT (f)); + + /* PRETEND is always false here. */ + adjust_frame_size (f, text_width, text_height, 1, false, Qsize); + return Qnil; } @@ -4035,11 +4116,9 @@ 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; @@ -4117,6 +4196,8 @@ gui_set_frame_parameters (struct frame *f, Lisp_Object alist) if (EQ (prop, Qwidth)) { + 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) @@ -4125,9 +4206,13 @@ gui_set_frame_parameters (struct frame *f, Lisp_Object alist) 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)) { + 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) @@ -4136,6 +4221,8 @@ gui_set_frame_parameters (struct frame *f, Lisp_Object alist) 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; @@ -4204,23 +4291,28 @@ gui_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_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) @@ -4293,9 +4385,6 @@ gui_set_frame_parameters (struct frame *f, Lisp_Object alist) { 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)) gui_set_fullscreen (f, fullscreen, old_value); @@ -5504,25 +5593,16 @@ 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 gui_figure_window_size (struct frame *f, Lisp_Object parms, bool tabbar_p, - bool toolbar_p, int *x_width, int *x_height) + 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. */ @@ -5537,8 +5617,12 @@ gui_figure_window_size (struct frame *f, Lisp_Object parms, bool tabbar_p, 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; @@ -5591,7 +5675,7 @@ gui_figure_window_size (struct frame *f, Lisp_Object parms, bool tabbar_p, /* 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 = 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); @@ -5605,9 +5689,8 @@ gui_figure_window_size (struct frame *f, Lisp_Object parms, bool tabbar_p, if ((XFIXNUM (XCDR (width)) < 0 || XFIXNUM (XCDR (width)) > INT_MAX)) xsignal1 (Qargs_out_of_range, XCDR (width)); - SET_FRAME_WIDTH (f, XFIXNUM (XCDR (width))); + text_width = XFIXNUM (XCDR (width)); f->inhibit_horizontal_resize = true; - *x_width = XFIXNUM (XCDR (width)); } else if (FLOATP (width)) { @@ -5621,7 +5704,7 @@ gui_figure_window_size (struct frame *f, Lisp_Object parms, bool tabbar_p, &parent_done, &outer_done, -1); if (new_width > -1) - SET_FRAME_WIDTH (f, new_width); + text_width = new_width; } } else @@ -5630,7 +5713,7 @@ gui_figure_window_size (struct frame *f, Lisp_Object parms, bool tabbar_p, if ((XFIXNUM (width) < 0 || XFIXNUM (width) > INT_MAX)) xsignal1 (Qargs_out_of_range, width); - SET_FRAME_WIDTH (f, XFIXNUM (width) * FRAME_COLUMN_WIDTH (f)); + text_width = XFIXNUM (width) * FRAME_COLUMN_WIDTH (f); } } @@ -5642,9 +5725,8 @@ gui_figure_window_size (struct frame *f, Lisp_Object parms, bool tabbar_p, if ((XFIXNUM (XCDR (height)) < 0 || XFIXNUM (XCDR (height)) > INT_MAX)) xsignal1 (Qargs_out_of_range, XCDR (height)); - SET_FRAME_HEIGHT (f, XFIXNUM (XCDR (height))); + text_height = XFIXNUM (XCDR (height)); f->inhibit_vertical_resize = true; - *x_height = XFIXNUM (XCDR (height)); } else if (FLOATP (height)) { @@ -5658,7 +5740,7 @@ gui_figure_window_size (struct frame *f, Lisp_Object parms, bool tabbar_p, &parent_done, &outer_done, -1); if (new_height > -1) - SET_FRAME_HEIGHT (f, new_height); + text_height = new_height; } } else @@ -5667,7 +5749,7 @@ gui_figure_window_size (struct frame *f, Lisp_Object parms, bool tabbar_p, if ((XFIXNUM (height) < 0) || (XFIXNUM (height) > INT_MAX)) xsignal1 (Qargs_out_of_range, height); - SET_FRAME_HEIGHT (f, XFIXNUM (height) * FRAME_LINE_HEIGHT (f)); + text_height = XFIXNUM (height) * FRAME_LINE_HEIGHT (f); } } @@ -5679,6 +5761,9 @@ gui_figure_window_size (struct frame *f, Lisp_Object parms, bool tabbar_p, window_prompting |= PSize; } + 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, @@ -5986,39 +6071,17 @@ syms_of_frame (void) 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 (Qxg_frame_set_char_size_4, "xg-frame-set-char-size-4"); - 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_tab_bar, "update-frame-tab-bar"); - DEFSYM (Qupdate_frame_tool_bar, "update-frame-tool-bar"); - DEFSYM (Qfree_frame_tab_bar, "free-frame-tab-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"); @@ -6047,9 +6110,7 @@ syms_of_frame (void) 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"); @@ -6061,7 +6122,6 @@ syms_of_frame (void) DEFSYM (Qscroll_bar_width, "scroll-bar-width"); DEFSYM (Qsticky, "sticky"); DEFSYM (Qtitle, "title"); - DEFSYM (Qtab_bar_lines, "tab-bar-lines"); DEFSYM (Qtool_bar_lines, "tool-bar-lines"); DEFSYM (Qtool_bar_position, "tool-bar-position"); DEFSYM (Qunsplittable, "unsplittable"); diff --git a/src/frame.h b/src/frame.h index 0fd95e4dd3c..19ee6ac10e7 100644 --- a/src/frame.h +++ b/src/frame.h @@ -256,8 +256,8 @@ struct frame be used for output. */ bool_bf glyphs_initialized_p : 1; - /* Set to true in change_frame_size when size of frame changed - Clear the frame in clear_garbaged_frames if set. */ + /* Set to true in adjust_frame_size when one of the frame's sizes + changed. Clear the frame in clear_garbaged_frames if set. */ bool_bf resized_p : 1; /* Set to true if the default face for the frame has been @@ -415,10 +415,6 @@ struct frame bool_bf no_special_glyphs : 1; #endif /* HAVE_WINDOW_SYSTEM */ - /* Whether new_height and new_width shall be interpreted - in pixels. */ - bool_bf new_pixelwise : 1; - /* True means set_window_size_hook requests can be processed for this frame. */ bool_bf can_set_window_size : 1; @@ -426,11 +422,23 @@ struct frame /* Set to true after this frame was made by `make-frame'. */ bool_bf after_make_frame : 1; - /* Whether the tab bar height change should be taken into account. */ + /* Two sticky flags, that are both false when a frame is created. + 'display_tab_bar' sets the former to true the first time it + displays the tab bar. When the former is true, the next call of + 'x_change_tab_bar_height' and associates sets the latter true and + tries to adjust the frame height in a way that the now valid pixel + height of the tab bar is taken into account by the frame's native + height. */ bool_bf tab_bar_redisplayed : 1; bool_bf tab_bar_resized : 1; - /* Whether the tool bar height change should be taken into account. */ + /* Two sticky flags, that are both false when a frame is created. + 'redisplay_tool_bar' sets the former to true the first time it + displays the tool bar. When the former is true, the next call of + 'x_change_tool_bar_height' and associates sets the latter true and + tries to adjust the frame height in a way that the now valid pixel + height of the tool bar is taken into account by the frame's native + height. */ bool_bf tool_bar_redisplayed : 1; bool_bf tool_bar_resized : 1; @@ -461,7 +469,7 @@ struct frame last time run_window_change_functions was called on it. */ ptrdiff_t number_of_windows; - /* Number of lines (rounded up) of tab bar. REMOVE THIS */ + /* Number of frame lines (rounded up) of tab bar. */ int tab_bar_lines; /* Height of frame internal tab bar in pixels. */ @@ -470,7 +478,7 @@ struct frame int n_tab_bar_rows; int n_tab_bar_items; - /* Number of lines (rounded up) of tool bar. REMOVE THIS */ + /* Number of frame lines (rounded up) of tool bar. */ int tool_bar_lines; /* Height of frame internal tool bar in pixels. */ @@ -492,39 +500,24 @@ struct frame /* Cost of deleting n lines on this frame. */ int *delete_n_lines_cost; - /* Text width of this frame (excluding fringes, vertical scroll bar - and internal border widths) and text height (excluding menu bar, - tool bar, horizontal scroll bar and internal border widths) in - units of canonical characters. */ + /* Text width and height of this frame in (and maybe rounded to) frame + columns and lines. */ int text_cols, text_lines; - - /* Total width of this frame (including fringes, vertical scroll bar - and internal border widths) and total height (including menu bar, - tool bar, horizontal scroll bar and internal border widths) in - units of canonical characters. */ - int total_cols, total_lines; - - /* Text width of this frame (excluding fringes, vertical scroll bar - and internal border widths) and text height (excluding menu bar, - tool bar, horizontal scroll bar and internal border widths) in - pixels. */ + /* Text width and height of this frame in pixels. */ int text_width, text_height; - /* New text height and width for pending size change. 0 if no change - pending. These values represent pixels or canonical character units - according to the value of new_pixelwise and correlate to the - text width/height of the frame. */ + /* Native width of this frame in (and maybe rounded to) frame columns + and lines. */ + int total_cols, total_lines; + /* Native width and height of this frame in pixels. */ + int pixel_width, pixel_height; + /* New native width and height of this frame for pending size change, + in pixels. -1 if no change pending. */ int new_width, new_height; /* Pixel position of the frame window (x and y offsets in root window). */ int left_pos, top_pos; - /* Total width of this frame (including fringes, vertical scroll bar - and internal border widths) and total height (including internal - menu and tool bars, horizontal scroll bar and internal border - widths) in pixels. */ - int pixel_width, pixel_height; - /* This is the gravity value for the specified window position. */ int win_gravity; @@ -848,7 +841,6 @@ default_pixels_per_inch_y (void) /* FRAME_WINDOW_P tests whether the frame is a graphical window system frame. */ - #ifdef HAVE_X_WINDOWS #define FRAME_WINDOW_P(f) FRAME_X_P (f) #endif @@ -914,45 +906,36 @@ default_pixels_per_inch_y (void) # define FRAME_SCALE_FACTOR(f) 1 #endif -/* Pixel width of frame F. */ +/* Native width and height of frame F, in pixels and frame + columns/lines. */ #define FRAME_PIXEL_WIDTH(f) ((f)->pixel_width) - -/* Pixel height of frame F. */ #define FRAME_PIXEL_HEIGHT(f) ((f)->pixel_height) +#define FRAME_TOTAL_COLS(f) ((f)->total_cols) +#define FRAME_TOTAL_LINES(f) ((f)->total_lines) -/* Width of frame F, measured in canonical character columns, - not including scroll bars if any. */ -#define FRAME_COLS(f) (f)->text_cols - -/* Height of frame F, measured in canonical lines, including - non-toolkit menu bar and non-toolkit tool bar lines. */ -#define FRAME_LINES(f) (f)->text_lines - -/* Width of frame F, measured in pixels not including the width for - fringes, scroll bar, and internal borders. */ +/* Text width and height of frame F, in pixels and frame + columns/lines. */ #define FRAME_TEXT_WIDTH(f) (f)->text_width - -/* Height of frame F, measured in pixels not including the height - for scroll bar and internal borders. */ #define FRAME_TEXT_HEIGHT(f) (f)->text_height +#define FRAME_COLS(f) ((f)->text_cols) +#define FRAME_LINES(f) ((f)->text_lines) -/* Number of lines of frame F used for menu bar. - This is relevant on terminal frames and on - X Windows when not using the X toolkit. - These lines are counted in FRAME_LINES. */ -#define FRAME_MENU_BAR_LINES(f) (f)->menu_bar_lines +/* True if this frame should display an external menu bar. */ +#ifdef HAVE_EXT_MENU_BAR +#define FRAME_EXTERNAL_MENU_BAR(f) (f)->external_menu_bar +#else +#define FRAME_EXTERNAL_MENU_BAR(f) false +#endif -/* Pixel height of frame F's menu bar. */ +/* Size of frame F's internal menu bar in frame lines and pixels. */ +#define FRAME_MENU_BAR_LINES(f) (f)->menu_bar_lines #define FRAME_MENU_BAR_HEIGHT(f) (f)->menu_bar_height -/* Number of lines of frame F used for the tab-bar. */ +/* Size of frame F's tab bar in frame lines and pixels. */ #define FRAME_TAB_BAR_LINES(f) (f)->tab_bar_lines - -/* Pixel height of frame F's tab-bar. */ #define FRAME_TAB_BAR_HEIGHT(f) (f)->tab_bar_height -/* True if this frame should display a tool bar - in a way that does not use any text lines. */ +/* True if this frame should display an external tool bar. */ #ifdef HAVE_EXT_TOOL_BAR #define FRAME_EXTERNAL_TOOL_BAR(f) (f)->external_tool_bar #else @@ -966,27 +949,21 @@ default_pixels_per_inch_y (void) #define FRAME_TOOL_BAR_POSITION(f) ((void) (f), Qtop) #endif -/* Number of lines of frame F used for the tool-bar. */ +/* Size of frame F's internal tool bar in frame lines and pixels. */ #define FRAME_TOOL_BAR_LINES(f) (f)->tool_bar_lines - -/* Pixel height of frame F's tool-bar. */ #define FRAME_TOOL_BAR_HEIGHT(f) (f)->tool_bar_height -/* Lines above the top-most window in frame F. */ -#define FRAME_TOP_MARGIN(F) \ - (FRAME_MENU_BAR_LINES (F) + FRAME_TAB_BAR_LINES (F) + FRAME_TOOL_BAR_LINES (F)) +/* Height of frame F's top margin in frame lines. */ +#define FRAME_TOP_MARGIN(F) \ + (FRAME_MENU_BAR_LINES (F) \ + + FRAME_TAB_BAR_LINES (F) \ + + FRAME_TOOL_BAR_LINES (F)) /* Pixel height of frame F's top margin. */ -#define FRAME_TOP_MARGIN_HEIGHT(F) \ - (FRAME_MENU_BAR_HEIGHT (F) + FRAME_TAB_BAR_HEIGHT (F) + FRAME_TOOL_BAR_HEIGHT (F)) - -/* True if this frame should display a menu bar - in a way that does not use any text lines. */ -#ifdef HAVE_EXT_MENU_BAR -#define FRAME_EXTERNAL_MENU_BAR(f) (f)->external_menu_bar -#else -#define FRAME_EXTERNAL_MENU_BAR(f) false -#endif +#define FRAME_TOP_MARGIN_HEIGHT(F) \ + (FRAME_MENU_BAR_HEIGHT (F) \ + + FRAME_TAB_BAR_HEIGHT (F) \ + + FRAME_TOOL_BAR_HEIGHT (F)) /* True if frame F is currently visible. */ #define FRAME_VISIBLE_P(f) (f)->visible @@ -1183,48 +1160,6 @@ default_pixels_per_inch_y (void) ? FRAME_CONFIG_SCROLL_BAR_LINES (f) \ : 0) -/* Total width of frame F, in columns (characters), - including the width used by scroll bars if any. */ -#define FRAME_TOTAL_COLS(f) ((f)->total_cols) - -/* Total height of frame F, in lines (characters), - including the height used by scroll bars if any. */ -#define FRAME_TOTAL_LINES(f) ((f)->total_lines) - -/* Set the character widths of frame F. WIDTH specifies a nominal - character text width. */ -#define SET_FRAME_COLS(f, width) \ - ((f)->text_cols = (width), \ - (f)->total_cols = ((width) \ - + FRAME_SCROLL_BAR_COLS (f) \ - + FRAME_FRINGE_COLS (f))) - -/* Set the character heights of frame F. HEIGHT specifies a nominal - character text height. */ -#define SET_FRAME_LINES(f, height) \ - ((f)->text_lines = (height), \ - (f)->total_lines = ((height) \ - + FRAME_TOP_MARGIN (f) \ - + FRAME_SCROLL_BAR_LINES (f))) - -/* Set the widths of frame F. WIDTH specifies a nominal pixel text - width. */ -#define SET_FRAME_WIDTH(f, width) \ - ((f)->text_width = (width), \ - (f)->pixel_width = ((width) \ - + FRAME_SCROLL_BAR_AREA_WIDTH (f) \ - + FRAME_TOTAL_FRINGE_WIDTH (f) \ - + 2 * FRAME_INTERNAL_BORDER_WIDTH (f))) - -/* Set the heights of frame F. HEIGHT specifies a nominal pixel text - height. */ -#define SET_FRAME_HEIGHT(f, height) \ - ((f)->text_height = (height), \ - (f)->pixel_height = ((height) \ - + FRAME_TOP_MARGIN_HEIGHT (f) \ - + FRAME_SCROLL_BAR_AREA_HEIGHT (f) \ - + 2 * FRAME_INTERNAL_BORDER_WIDTH (f))) - /* Maximum + 1 legitimate value for FRAME_CURSOR_X. */ #define FRAME_CURSOR_X_LIMIT(f) \ (FRAME_COLS (f) + FRAME_LEFT_SCROLL_BAR_COLS (f)) @@ -1245,7 +1180,6 @@ default_pixels_per_inch_y (void) #define FRAME_BACKGROUND_PIXEL(f) ((f)->background_pixel) /* Return a pointer to the face cache of frame F. */ - #define FRAME_FACE_CACHE(F) (F)->face_cache /* Return the size of message_buf of the frame F. We multiply the @@ -1271,15 +1205,13 @@ default_pixels_per_inch_y (void) This macro is a holdover from a time when multiple frames weren't always supported. An alternate definition of the macro would expand to something which executes the statement once. */ - -#define FOR_EACH_FRAME(list_var, frame_var) \ - for ((list_var) = Vframe_list; \ - (CONSP (list_var) \ +#define FOR_EACH_FRAME(list_var, frame_var) \ + for ((list_var) = Vframe_list; \ + (CONSP (list_var) \ && (frame_var = XCAR (list_var), true)); \ list_var = XCDR (list_var)) /* Reflect mouse movement when a complete frame update is performed. */ - #define FRAME_MOUSE_UPDATE(frame) \ do { \ Mouse_HLInfo *hlinfo = MOUSE_HL_INFO (frame); \ @@ -1294,8 +1226,7 @@ default_pixels_per_inch_y (void) } while (false) /* Handy macro to construct an argument to Fmodify_frame_parameters. */ - -#define AUTO_FRAME_ARG(name, parameter, value) \ +#define AUTO_FRAME_ARG(name, parameter, value) \ AUTO_LIST1 (name, AUTO_CONS_EXPR (parameter, value)) /* False means there are no visible garbaged frames. */ @@ -1305,7 +1236,6 @@ extern bool frame_garbaged; We call redisplay_other_windows to make sure the frame gets redisplayed if some changes were applied to it while it wasn't visible (and hence wasn't redisplayed). */ - INLINE void SET_FRAME_VISIBLE (struct frame *f, int v) { @@ -1320,9 +1250,8 @@ SET_FRAME_VISIBLE (struct frame *f, int v) f->visible = v; } -/* Set iconify of frame F. */ - -#define SET_FRAME_ICONIFIED(f, i) \ +/* Set iconified status of frame F. */ +#define SET_FRAME_ICONIFIED(f, i) \ (f)->iconified = (eassert (0 <= (i) && (i) <= 1), (i)) extern Lisp_Object selected_frame; @@ -1369,11 +1298,14 @@ extern void frame_make_pointer_invisible (struct frame *); extern void frame_make_pointer_visible (struct frame *); extern Lisp_Object delete_frame (Lisp_Object, Lisp_Object); extern bool frame_inhibit_resize (struct frame *, bool, Lisp_Object); -extern void adjust_frame_size (struct frame *, int, int, int, bool, Lisp_Object); -extern void frame_size_history_add (struct frame *f, Lisp_Object fun_symbol, - int width, int height, Lisp_Object rest); +extern void adjust_frame_size (struct frame *, int, int, int, bool, + Lisp_Object); extern Lisp_Object mouse_position (bool); - +extern int frame_windows_min_size (Lisp_Object, Lisp_Object, Lisp_Object, + Lisp_Object); +extern void frame_size_history_plain (struct frame *, Lisp_Object); +extern void frame_size_history_extra (struct frame *, Lisp_Object, + int, int, int, int, int, int); extern Lisp_Object Vframe_list; /* Value is a pointer to the selected frame. If the selected frame @@ -1652,12 +1584,11 @@ IMAGE_OPT_FROM_ID (struct frame *f, int id) - FRAME_SCROLL_BAR_AREA_HEIGHT (f) \ - 2 * FRAME_INTERNAL_BORDER_WIDTH (f)) -/* Return the width/height reserved for the windows of frame F. */ -#define FRAME_WINDOWS_WIDTH(f) \ +#define FRAME_INNER_WIDTH(f) \ (FRAME_PIXEL_WIDTH (f) \ - 2 * FRAME_INTERNAL_BORDER_WIDTH (f)) -#define FRAME_WINDOWS_HEIGHT(f) \ +#define FRAME_INNER_HEIGHT(f) \ (FRAME_PIXEL_HEIGHT (f) \ - FRAME_TOP_MARGIN_HEIGHT (f) \ - 2 * FRAME_INTERNAL_BORDER_WIDTH (f)) @@ -1701,7 +1632,7 @@ extern void gui_set_horizontal_scroll_bars (struct frame *, Lisp_Object, Lisp_Ob extern void gui_set_scroll_bar_width (struct frame *, Lisp_Object, Lisp_Object); extern void gui_set_scroll_bar_height (struct frame *, Lisp_Object, Lisp_Object); -extern long gui_figure_window_size (struct frame *, Lisp_Object, bool, bool, int *, int *); +extern long gui_figure_window_size (struct frame *, Lisp_Object, bool, bool); extern void gui_set_alpha (struct frame *, Lisp_Object, Lisp_Object); extern void gui_set_no_special_glyphs (struct frame *, Lisp_Object, Lisp_Object); diff --git a/src/gtkutil.c b/src/gtkutil.c index 4634c35dd4c..4ad172bb486 100644 --- a/src/gtkutil.c +++ b/src/gtkutil.c @@ -910,70 +910,58 @@ xg_set_geometry (struct frame *f) } } -/* Function to handle resize of our frame. As we have a Gtk+ tool bar - and a Gtk+ menu bar, we get resize events for the edit part of the - frame only. We let Gtk+ deal with the Gtk+ parts. - F is the frame to resize. - PIXELWIDTH, PIXELHEIGHT is the new size in pixels. */ - +/** Function to handle resize of native frame F to WIDTH and HEIGHT + pixels after we got a ConfigureNotify event. */ void -xg_frame_resized (struct frame *f, int pixelwidth, int pixelheight) +xg_frame_resized (struct frame *f, int width, int height) { - int width, height; - - if (pixelwidth == -1 && pixelheight == -1) + /* Ignore case where size of native rectangle didn't change. */ + if (width != FRAME_PIXEL_WIDTH (f) || height != FRAME_PIXEL_HEIGHT (f) + || (delayed_size_change + && (width != f->new_width || height != f->new_height))) { - if (FRAME_GTK_WIDGET (f) && gtk_widget_get_mapped (FRAME_GTK_WIDGET (f))) - gdk_window_get_geometry (gtk_widget_get_window (FRAME_GTK_WIDGET (f)), - 0, 0, &pixelwidth, &pixelheight); - else - return; - } + if (CONSP (frame_size_history)) + frame_size_history_extra + (f, build_string ("xg_frame_resized, changed"), + FRAME_PIXEL_WIDTH (f), FRAME_PIXEL_HEIGHT (f), width, height, + delayed_size_change ? f->new_width : -1, + delayed_size_change ? f->new_height : -1); - width = FRAME_PIXEL_TO_TEXT_WIDTH (f, pixelwidth); - height = FRAME_PIXEL_TO_TEXT_HEIGHT (f, pixelheight); - - frame_size_history_add - (f, Qxg_frame_resized, width, height, Qnil); - - if (width != FRAME_TEXT_WIDTH (f) - || height != FRAME_TEXT_HEIGHT (f) - || pixelwidth != FRAME_PIXEL_WIDTH (f) - || pixelheight != FRAME_PIXEL_HEIGHT (f)) - { FRAME_RIF (f)->clear_under_internal_border (f); - change_frame_size (f, width, height, 0, 1, 0, 1); + change_frame_size (f, width, height, false, true, false); SET_FRAME_GARBAGED (f); cancel_mouse_face (f); } + else if (CONSP (frame_size_history)) + frame_size_history_extra + (f, build_string ("xg_frame_resized, unchanged"), + FRAME_PIXEL_WIDTH (f), FRAME_PIXEL_HEIGHT (f), width, height, + delayed_size_change ? f->new_width : -1, + delayed_size_change ? f->new_height : -1); + } /** Resize the outer window of frame F. WIDTH and HEIGHT are the new - pixel sizes of F's text area. */ + native pixel sizes of F. */ void xg_frame_set_char_size (struct frame *f, int width, int height) { - int pixelwidth = FRAME_TEXT_TO_PIXEL_WIDTH (f, width); - int pixelheight = FRAME_TEXT_TO_PIXEL_HEIGHT (f, height); Lisp_Object fullscreen = get_frame_param (f, Qfullscreen); gint gwidth, gheight; - int totalheight - = pixelheight + FRAME_TOOLBAR_HEIGHT (f) + FRAME_MENUBAR_HEIGHT (f); - int totalwidth = pixelwidth + FRAME_TOOLBAR_WIDTH (f); + int outer_height + = height + FRAME_TOOLBAR_HEIGHT (f) + FRAME_MENUBAR_HEIGHT (f); + int outer_width = width + FRAME_TOOLBAR_WIDTH (f); bool was_visible = false; bool hide_child_frame; - if (FRAME_PIXEL_HEIGHT (f) == 0) - return; - gtk_window_get_size (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)), &gwidth, &gheight); /* Do this before resize, as we don't know yet if we will be resized. */ FRAME_RIF (f)->clear_under_internal_border (f); - totalheight /= xg_get_scale (f); - totalwidth /= xg_get_scale (f); + outer_height /= xg_get_scale (f); + outer_width /= xg_get_scale (f); x_wm_set_size_hint (f, 0, 0); @@ -986,35 +974,19 @@ xg_frame_set_char_size (struct frame *f, int width, int height) manager will abolish it. At least the respective size should remain unchanged but giving the frame back its normal size will be broken ... */ - if (EQ (fullscreen, Qfullwidth) && width == FRAME_TEXT_WIDTH (f)) - { - frame_size_history_add - (f, Qxg_frame_set_char_size_1, width, height, - list2i (gheight, totalheight)); - - gtk_window_resize (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)), - gwidth, totalheight); - } - else if (EQ (fullscreen, Qfullheight) && height == FRAME_TEXT_HEIGHT (f)) - { - frame_size_history_add - (f, Qxg_frame_set_char_size_2, width, height, - list2i (gwidth, totalwidth)); - - gtk_window_resize (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)), - totalwidth, gheight); - } + if (EQ (fullscreen, Qfullwidth) && width == FRAME_PIXEL_WIDTH (f)) + gtk_window_resize (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)), + gwidth, outer_height); + else if (EQ (fullscreen, Qfullheight) && height == FRAME_PIXEL_HEIGHT (f)) + gtk_window_resize (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)), + outer_width, gheight); else if (FRAME_PARENT_FRAME (f) && FRAME_VISIBLE_P (f)) { was_visible = true; hide_child_frame = EQ (x_gtk_resize_child_frames, Qhide); - if (totalwidth != gwidth || totalheight != gheight) + if (outer_width != gwidth || outer_height != gheight) { - frame_size_history_add - (f, Qxg_frame_set_char_size_4, width, height, - list2i (totalwidth, totalheight)); - if (hide_child_frame) { block_input (); @@ -1023,7 +995,7 @@ xg_frame_set_char_size (struct frame *f, int width, int height) } gtk_window_resize (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)), - totalwidth, totalheight); + outer_width, outer_height); if (hide_child_frame) { @@ -1037,11 +1009,8 @@ xg_frame_set_char_size (struct frame *f, int width, int height) } else { - frame_size_history_add - (f, Qxg_frame_set_char_size_3, width, height, - list2i (totalwidth, totalheight)); gtk_window_resize (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)), - totalwidth, totalheight); + outer_width, outer_height); fullscreen = Qnil; } @@ -1062,6 +1031,12 @@ xg_frame_set_char_size (struct frame *f, int width, int height) gdk_flush (); x_wait_for_event (f, ConfigureNotify); + if (CONSP (frame_size_history)) + frame_size_history_extra + (f, build_string ("xg_frame_set_char_size, visible"), + FRAME_PIXEL_WIDTH (f), FRAME_PIXEL_HEIGHT (f), width, height, + f->new_width, f->new_height); + if (!NILP (fullscreen)) /* Try to restore fullscreen state. */ { @@ -1070,8 +1045,17 @@ xg_frame_set_char_size (struct frame *f, int width, int height) } } else - adjust_frame_size (f, width, height, 5, 0, Qxg_frame_set_char_size); - + { + if (CONSP (frame_size_history)) + frame_size_history_extra + (f, build_string ("xg_frame_set_char_size, invisible"), + FRAME_PIXEL_WIDTH (f), FRAME_PIXEL_HEIGHT (f), width, height, + f->new_width, f->new_height); + + adjust_frame_size (f, FRAME_PIXEL_TO_TEXT_WIDTH (f, width), + FRAME_PIXEL_TO_TEXT_HEIGHT (f, height), + 5, 0, Qxg_frame_set_char_size); + } } /* Handle height/width changes (i.e. add/remove/move menu/toolbar). @@ -1186,7 +1170,8 @@ style_changed_cb (GObject *go, { FRAME_TERMINAL (f)->set_scroll_bar_default_width_hook (f); FRAME_TERMINAL (f)->set_scroll_bar_default_height_hook (f); - xg_frame_set_char_size (f, FRAME_TEXT_WIDTH (f), FRAME_TEXT_HEIGHT (f)); + xg_frame_set_char_size (f, FRAME_PIXEL_WIDTH (f), + FRAME_PIXEL_HEIGHT (f)); } } } @@ -4589,10 +4574,7 @@ tb_size_cb (GtkWidget *widget, struct frame *f = user_data; if (xg_update_tool_bar_sizes (f)) - { - frame_size_history_add (f, Qtb_size_cb, 0, 0, Qnil); - adjust_frame_size (f, -1, -1, 5, 0, Qtool_bar_lines); - } + adjust_frame_size (f, -1, -1, 2, false, Qtool_bar_lines); } /* Create a tool bar for frame F. */ @@ -5219,23 +5201,10 @@ update_frame_tool_bar (struct frame *f) xg_pack_tool_bar (f, FRAME_TOOL_BAR_POSITION (f)); gtk_widget_show_all (x->toolbar_widget); if (xg_update_tool_bar_sizes (f)) - { - int inhibit - = ((f->after_make_frame - && !f->tool_bar_resized - && (EQ (frame_inhibit_implied_resize, Qt) - || (CONSP (frame_inhibit_implied_resize) - && !NILP (Fmemq (Qtool_bar_lines, - frame_inhibit_implied_resize)))) - /* This will probably fail to DTRT in the - fullheight/-width cases. */ - && NILP (get_frame_param (f, Qfullscreen))) - ? 0 - : 2); - - frame_size_history_add (f, Qupdate_frame_tool_bar, 0, 0, Qnil); - adjust_frame_size (f, -1, -1, inhibit, 0, Qtool_bar_lines); - } + /* It's not entirely clear whether here we want a treatment + similar to that for frames with internal tool bar. */ + adjust_frame_size (f, -1, -1, 2, 0, Qtool_bar_lines); + f->tool_bar_resized = f->tool_bar_redisplayed; } @@ -5284,7 +5253,6 @@ free_frame_tool_bar (struct frame *f) NULL); } - frame_size_history_add (f, Qfree_frame_tool_bar, 0, 0, Qnil); adjust_frame_size (f, -1, -1, 2, 0, Qtool_bar_lines); unblock_input (); @@ -5316,11 +5284,7 @@ xg_change_toolbar_position (struct frame *f, Lisp_Object pos) g_object_unref (top_widget); if (xg_update_tool_bar_sizes (f)) - { - frame_size_history_add (f, Qxg_change_toolbar_position, 0, 0, Qnil); - adjust_frame_size (f, -1, -1, 2, 0, Qtool_bar_lines); - } - + adjust_frame_size (f, -1, -1, 2, 0, Qtool_bar_lines); unblock_input (); } diff --git a/src/keyboard.c b/src/keyboard.c index e9236fee1aa..47b5e590245 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -10665,10 +10665,7 @@ On such systems, Emacs starts a subshell instead of suspending. */) with a window system; but suspend should be disabled in that case. */ get_tty_size (fileno (CURTTY ()->input), &width, &height); if (width != old_width || height != old_height) - change_frame_size (SELECTED_FRAME (), width, - height - FRAME_MENU_BAR_LINES (SELECTED_FRAME ()) - - FRAME_TAB_BAR_LINES (SELECTED_FRAME ()), - 0, 0, 0, 0); + change_frame_size (SELECTED_FRAME (), width, height, false, false, false); run_hook (intern ("suspend-resume-hook")); diff --git a/src/nsfns.m b/src/nsfns.m index 5c4cc915e7c..054777aa66f 100644 --- a/src/nsfns.m +++ b/src/nsfns.m @@ -669,21 +669,9 @@ ns_set_tool_bar_lines (struct frame *f, Lisp_Object value, Lisp_Object oldval) } { - int inhibit - = ((f->after_make_frame - && !f->tool_bar_resized - && (EQ (frame_inhibit_implied_resize, Qt) - || (CONSP (frame_inhibit_implied_resize) - && !NILP (Fmemq (Qtool_bar_lines, - frame_inhibit_implied_resize)))) - && NILP (get_frame_param (f, Qfullscreen))) - ? 0 - : 2); - NSTRACE_MSG ("inhibit:%d", inhibit); - frame_size_history_add (f, Qupdate_frame_tool_bar, 0, 0, Qnil); - adjust_frame_size (f, -1, -1, inhibit, 0, Qtool_bar_lines); + adjust_frame_size (f, -1, -1, 2, false, Qtool_bar_lines); } } @@ -1332,8 +1320,7 @@ DEFUN ("x-create-frame", Fx_create_frame, Sx_create_frame, RES_TYPE_STRING); parms = get_geometry_from_preferences (dpyinfo, parms); - window_prompting = gui_figure_window_size (f, parms, false, true, - &x_width, &x_height); + window_prompting = gui_figure_window_size (f, parms, false, true); tem = gui_display_get_arg (dpyinfo, parms, Qunsplittable, 0, 0, RES_TYPE_BOOLEAN); @@ -1400,13 +1387,8 @@ DEFUN ("x-create-frame", Fx_create_frame, Sx_create_frame, /* Allow set_window_size_hook, now. */ f->can_set_window_size = true; - if (x_width > 0) - SET_FRAME_WIDTH (f, x_width); - if (x_height > 0) - SET_FRAME_HEIGHT (f, x_height); - - adjust_frame_size (f, FRAME_TEXT_WIDTH (f), FRAME_TEXT_HEIGHT (f), 0, 1, - Qx_create_frame_2); + adjust_frame_size (f, FRAME_TEXT_WIDTH (f), FRAME_TEXT_HEIGHT (f), + 0, true, Qx_create_frame_2); if (! f->output_data.ns->explicit_parent) { diff --git a/src/nsterm.m b/src/nsterm.m index a6501100ca9..b135e359f5d 100644 --- a/src/nsterm.m +++ b/src/nsterm.m @@ -1876,10 +1876,9 @@ static void ns_set_window_size (struct frame *f, bool change_gravity, int width, - int height, - bool pixelwise) + int height) /* -------------------------------------------------------------------------- - Adjust window pixel size based on given character grid size + Adjust window pixel size based on native sizes WIDTH and HEIGHT. Impl is a bit more complex than other terms, need to do some internal clipping. -------------------------------------------------------------------------- */ @@ -1887,7 +1886,6 @@ ns_set_window_size (struct frame *f, EmacsView *view = FRAME_NS_VIEW (f); NSWindow *window = [view window]; NSRect wr = [window frame]; - int pixelwidth, pixelheight; int orig_height = wr.size.height; NSTRACE ("ns_set_window_size"); @@ -1896,24 +1894,13 @@ ns_set_window_size (struct frame *f, return; NSTRACE_RECT ("current", wr); - NSTRACE_MSG ("Width:%d Height:%d Pixelwise:%d", width, height, pixelwise); + NSTRACE_MSG ("Width:%d Height:%d", width, height); NSTRACE_MSG ("Font %d x %d", FRAME_COLUMN_WIDTH (f), FRAME_LINE_HEIGHT (f)); block_input (); - if (pixelwise) - { - pixelwidth = FRAME_TEXT_TO_PIXEL_WIDTH (f, width); - pixelheight = FRAME_TEXT_TO_PIXEL_HEIGHT (f, height); - } - else - { - pixelwidth = FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, width); - pixelheight = FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f, height); - } - - wr.size.width = pixelwidth + f->border_width; - wr.size.height = pixelheight; + wr.size.width = width + f->border_width; + wr.size.height = height; if (! [view isFullscreen]) wr.size.height += FRAME_NS_TITLEBAR_HEIGHT (f) + FRAME_TOOLBAR_HEIGHT (f); @@ -1926,21 +1913,10 @@ ns_set_window_size (struct frame *f, else wr.origin.y += orig_height - wr.size.height; - frame_size_history_add - (f, Qx_set_window_size_1, width, height, - list5 (Fcons (make_fixnum (pixelwidth), make_fixnum (pixelheight)), - Fcons (make_fixnum (wr.size.width), make_fixnum (wr.size.height)), - make_fixnum (f->border_width), - make_fixnum (FRAME_NS_TITLEBAR_HEIGHT (f)), - make_fixnum (FRAME_TOOLBAR_HEIGHT (f)))); - /* Usually it seems safe to delay changing the frame size, but when a series of actions are taken with no redisplay between them then we can end up using old values so don't delay here. */ - change_frame_size (f, - FRAME_PIXEL_TO_TEXT_WIDTH (f, pixelwidth), - FRAME_PIXEL_TO_TEXT_HEIGHT (f, pixelheight), - 0, NO, 0, 1); + change_frame_size (f, width, height, false, NO, false); [window setFrame:wr display:NO]; @@ -7359,10 +7335,7 @@ not_in_argv (NSString *arg) changes size, as Emacs may already know about the change. Unfortunately there doesn't seem to be a bullet-proof method of determining whether we need to call it or not. */ - change_frame_size (emacsframe, - FRAME_PIXEL_TO_TEXT_WIDTH (emacsframe, neww), - FRAME_PIXEL_TO_TEXT_HEIGHT (emacsframe, newh), - 0, YES, 0, 1); + change_frame_size (emacsframe, neww, newh, false, YES, false); SET_FRAME_GARBAGED (emacsframe); cancel_mouse_face (emacsframe); diff --git a/src/term.c b/src/term.c index 1059b0669a7..c995a4499cf 100644 --- a/src/term.c +++ b/src/term.c @@ -2356,9 +2356,7 @@ frame's terminal). */) was suspended. */ get_tty_size (fileno (t->display_info.tty->input), &width, &height); if (width != old_width || height != old_height) - change_frame_size (f, width, height - FRAME_MENU_BAR_LINES (f) - - FRAME_TAB_BAR_LINES (f), - 0, 0, 0, 0); + change_frame_size (f, width, height, false, false, false); SET_FRAME_VISIBLE (XFRAME (t->display_info.tty->top_frame), 1); } diff --git a/src/termhooks.h b/src/termhooks.h index 3800679e803..1d3cdc8fe8d 100644 --- a/src/termhooks.h +++ b/src/termhooks.h @@ -583,7 +583,7 @@ struct terminal window gravity for this size change and subsequent size changes. Otherwise we leave the window gravity unchanged. */ void (*set_window_size_hook) (struct frame *f, bool change_gravity, - int width, int height, bool pixelwise); + int width, int height); /* CHANGE_GRAVITY is 1 when calling from Fset_frame_position, to really change the position, and 0 when calling from diff --git a/src/w32fns.c b/src/w32fns.c index c07f32ab0cc..66baeaecbdb 100644 --- a/src/w32fns.c +++ b/src/w32fns.c @@ -1701,7 +1701,7 @@ w32_change_tab_bar_height (struct frame *f, int height) int unit = FRAME_LINE_HEIGHT (f); int old_height = FRAME_TAB_BAR_HEIGHT (f); int lines = (height + unit - 1) / unit; - Lisp_Object fullscreen; + Lisp_Object fullscreen = get_frame_param (f, Qfullscreen); /* Make sure we redisplay all windows in this frame. */ fset_redisplay (f); @@ -1728,25 +1728,21 @@ w32_change_tab_bar_height (struct frame *f, int height) if ((height < old_height) && WINDOWP (f->tab_bar_window)) clear_glyph_matrix (XWINDOW (f->tab_bar_window)->current_matrix); - /* Recalculate tabbar height. */ - f->n_tab_bar_rows = 0; - if (old_height == 0 - && (!f->after_make_frame - || NILP (frame_inhibit_implied_resize) - || (CONSP (frame_inhibit_implied_resize) - && NILP (Fmemq (Qtab_bar_lines, frame_inhibit_implied_resize))))) - f->tab_bar_redisplayed = f->tab_bar_resized = false; - - adjust_frame_size (f, -1, -1, - ((!f->tab_bar_resized - && (NILP (fullscreen = - get_frame_param (f, Qfullscreen)) - || EQ (fullscreen, Qfullwidth))) ? 1 - : (old_height == 0 || height == 0) ? 2 - : 4), - false, Qtab_bar_lines); - - f->tab_bar_resized = f->tab_bar_redisplayed; + if (!f->tab_bar_resized) + { + /* As long as tab_bar_resized is false, effectively try to change + F's native height. */ + if (NILP (fullscreen) || EQ (fullscreen, Qfullwidth)) + adjust_frame_size (f, FRAME_TEXT_WIDTH (f), FRAME_TEXT_HEIGHT (f), + 1, false, Qtab_bar_lines); + else + adjust_frame_size (f, -1, -1, 4, false, Qtab_bar_lines); + + f->tab_bar_resized = f->tab_bar_redisplayed; + } + else + /* Any other change may leave the native size of F alone. */ + adjust_frame_size (f, -1, -1, 3, false, Qtab_bar_lines); /* adjust_frame_size might not have done anything, garbage frame here. */ @@ -1790,7 +1786,7 @@ w32_change_tool_bar_height (struct frame *f, int height) int unit = FRAME_LINE_HEIGHT (f); int old_height = FRAME_TOOL_BAR_HEIGHT (f); int lines = (height + unit - 1) / unit; - Lisp_Object fullscreen; + Lisp_Object fullscreen = get_frame_param (f, Qfullscreen); /* Make sure we redisplay all windows in this frame. */ windows_or_buffers_changed = 23; @@ -1811,25 +1807,21 @@ w32_change_tool_bar_height (struct frame *f, int height) if ((height < old_height) && WINDOWP (f->tool_bar_window)) clear_glyph_matrix (XWINDOW (f->tool_bar_window)->current_matrix); - /* Recalculate toolbar height. */ - f->n_tool_bar_rows = 0; - if (old_height == 0 - && (!f->after_make_frame - || NILP (frame_inhibit_implied_resize) - || (CONSP (frame_inhibit_implied_resize) - && NILP (Fmemq (Qtool_bar_lines, frame_inhibit_implied_resize))))) - f->tool_bar_redisplayed = f->tool_bar_resized = false; - - adjust_frame_size (f, -1, -1, - ((!f->tool_bar_resized - && (NILP (fullscreen = - get_frame_param (f, Qfullscreen)) - || EQ (fullscreen, Qfullwidth))) ? 1 - : (old_height == 0 || height == 0) ? 2 - : 4), - false, Qtool_bar_lines); - - f->tool_bar_resized = f->tool_bar_redisplayed; + if (!f->tool_bar_resized) + { + /* As long as tool_bar_resized is false, effectively try to change + F's native height. */ + if (NILP (fullscreen) || EQ (fullscreen, Qfullwidth)) + adjust_frame_size (f, FRAME_TEXT_WIDTH (f), FRAME_TEXT_HEIGHT (f), + 1, false, Qtool_bar_lines); + else + adjust_frame_size (f, -1, -1, 4, false, Qtool_bar_lines); + + f->tool_bar_resized = f->tool_bar_redisplayed; + } + else + /* Any other change may leave the native size of F alone. */ + adjust_frame_size (f, -1, -1, 3, false, Qtool_bar_lines); /* adjust_frame_size might not have done anything, garbage frame here. */ @@ -5718,7 +5710,6 @@ DEFUN ("x-create-frame", Fx_create_frame, Sx_create_frame, struct w32_display_info *dpyinfo = NULL; Lisp_Object parent, parent_frame; struct kboard *kb; - int x_width = 0, x_height = 0; if (!FRAME_W32_P (SELECTED_FRAME ()) && !FRAME_INITIAL_P (SELECTED_FRAME ())) @@ -6045,8 +6036,7 @@ DEFUN ("x-create-frame", Fx_create_frame, Sx_create_frame, f->output_data.w32->current_cursor = f->output_data.w32->nontext_cursor; - window_prompting = gui_figure_window_size (f, parameters, true, true, - &x_width, &x_height); + window_prompting = gui_figure_window_size (f, parameters, true, true); tem = gui_display_get_arg (dpyinfo, parameters, Qunsplittable, 0, 0, RES_TYPE_BOOLEAN); @@ -6081,11 +6071,6 @@ DEFUN ("x-create-frame", Fx_create_frame, Sx_create_frame, /* Allow set_window_size_hook, now. */ f->can_set_window_size = true; - if (x_width > 0) - SET_FRAME_WIDTH (f, x_width); - if (x_height > 0) - SET_FRAME_HEIGHT (f, x_height); - /* Tell the server what size and position, etc, we want, and how badly we want them. This should be done after we have the menu bar so that its size can be taken into account. */ @@ -6093,8 +6078,8 @@ DEFUN ("x-create-frame", Fx_create_frame, Sx_create_frame, w32_wm_set_size_hint (f, window_prompting, false); unblock_input (); - adjust_frame_size (f, FRAME_TEXT_WIDTH (f), FRAME_TEXT_HEIGHT (f), 0, true, - Qx_create_frame_2); + adjust_frame_size (f, FRAME_TEXT_WIDTH (f), FRAME_TEXT_HEIGHT (f), + 0, true, Qx_create_frame_2); /* Process fullscreen parameter here in the hope that normalizing a fullheight/fullwidth frame will produce the size set by the last @@ -6888,11 +6873,9 @@ w32_create_tip_frame (struct w32_display_info *dpyinfo, Lisp_Object parms) struct frame *f; Lisp_Object frame; Lisp_Object name; - int width, height; ptrdiff_t count = SPECPDL_INDEX (); struct kboard *kb; bool face_change_before = face_change; - int x_width = 0, x_height = 0; /* Use this general default value to start with until we know if this frame has a specified name. */ @@ -7013,7 +6996,7 @@ w32_create_tip_frame (struct w32_display_info *dpyinfo, Lisp_Object parms) f->output_data.w32->parent_desc = FRAME_DISPLAY_INFO (f)->root_window; f->output_data.w32->explicit_parent = false; - gui_figure_window_size (f, parms, true, true, &x_width, &x_height); + gui_figure_window_size (f, parms, true, true); /* No fringes on tip frame. */ f->fringe_cols = 0; @@ -7039,15 +7022,6 @@ w32_create_tip_frame (struct w32_display_info *dpyinfo, Lisp_Object parms) gui_default_parameter (f, parms, Qalpha, Qnil, "alpha", "Alpha", RES_TYPE_NUMBER); - /* Dimensions, especially FRAME_LINES (f), must be done via - change_frame_size. Change will not be effected unless different - from the current FRAME_LINES (f). */ - width = FRAME_COLS (f); - height = FRAME_LINES (f); - SET_FRAME_COLS (f, 0); - SET_FRAME_LINES (f, 0); - adjust_frame_size (f, width * FRAME_COLUMN_WIDTH (f), - height * FRAME_LINE_HEIGHT (f), 0, true, Qtip_frame); /* Add `tooltip' frame parameter's default value. */ if (NILP (Fframe_parameter (frame, Qtooltip))) Fmodify_frame_parameters (frame, Fcons (Fcons (Qtooltip, Qt), Qnil)); @@ -7088,6 +7062,8 @@ w32_create_tip_frame (struct w32_display_info *dpyinfo, Lisp_Object parms) visible won't work. */ Vframe_list = Fcons (frame, Vframe_list); f->can_set_window_size = true; + adjust_frame_size (f, FRAME_TEXT_WIDTH (f), FRAME_TEXT_HEIGHT (f), + 0, true, Qtip_frame); /* Setting attributes of faces of the tooltip frame from resources and similar will set face_change, which leads to the diff --git a/src/w32inevt.c b/src/w32inevt.c index 1a80a001974..1255072b7f3 100644 --- a/src/w32inevt.c +++ b/src/w32inevt.c @@ -608,9 +608,7 @@ resize_event (WINDOW_BUFFER_SIZE_RECORD *event) { struct frame *f = get_frame (); - change_frame_size (f, event->dwSize.X, event->dwSize.Y - - FRAME_MENU_BAR_LINES (f) - - FRAME_TAB_BAR_LINES (f), 0, 1, 0, 0); + change_frame_size (f, event->dwSize.X, event->dwSize.Y, false, true, false); SET_FRAME_GARBAGED (f); } @@ -624,11 +622,9 @@ maybe_generate_resize_event (void) /* It is okay to call this unconditionally, since it will do nothing if the size hasn't actually changed. */ - change_frame_size (f, - 1 + info.srWindow.Right - info.srWindow.Left, - 1 + info.srWindow.Bottom - info.srWindow.Top - - FRAME_MENU_BAR_LINES (f) - - FRAME_TAB_BAR_LINES (f), 0, 1, 0, 0); + change_frame_size (f, 1 + info.srWindow.Right - info.srWindow.Left, + 1 + info.srWindow.Bottom - info.srWindow.Top, + false, true, false); } #if HAVE_W32NOTIFY diff --git a/src/w32term.c b/src/w32term.c index 361cf33c024..4f910296ecc 100644 --- a/src/w32term.c +++ b/src/w32term.c @@ -5352,7 +5352,7 @@ w32_read_socket (struct terminal *terminal, if (f) { RECT rect; - int /* rows, columns, */ width, height, text_width, text_height; + int /* rows, columns, */ width, height; if (GetClientRect (msg.msg.hwnd, &rect) /* GetClientRect evidently returns (0, 0, 0, 0) if @@ -5365,23 +5365,11 @@ w32_read_socket (struct terminal *terminal, { height = rect.bottom - rect.top; width = rect.right - rect.left; - text_width = FRAME_PIXEL_TO_TEXT_WIDTH (f, width); - text_height = FRAME_PIXEL_TO_TEXT_HEIGHT (f, height); - /* rows = FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f, height); */ - /* columns = FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f, width); */ - - /* TODO: Clip size to the screen dimensions. */ - - /* Even if the number of character rows and columns - has not changed, the font size may have changed, - so we need to check the pixel dimensions as well. */ - if (width != FRAME_PIXEL_WIDTH (f) - || height != FRAME_PIXEL_HEIGHT (f) - || text_width != FRAME_TEXT_WIDTH (f) - || text_height != FRAME_TEXT_HEIGHT (f)) + || height != FRAME_PIXEL_HEIGHT (f)) { - change_frame_size (f, text_width, text_height, 0, 1, 0, 1); + change_frame_size + (f, width, height, false, true, false); SET_FRAME_GARBAGED (f); cancel_mouse_face (f); f->win_gravity = NorthWestGravity; @@ -5565,7 +5553,7 @@ w32_read_socket (struct terminal *terminal, if (f && !FRAME_ICONIFIED_P (f) && msg.msg.wParam != SIZE_MINIMIZED) { RECT rect; - int /* rows, columns, */ width, height, text_width, text_height; + int /* rows, columns, */ width, height; if (GetClientRect (msg.msg.hwnd, &rect) /* GetClientRect evidently returns (0, 0, 0, 0) if @@ -5578,23 +5566,12 @@ w32_read_socket (struct terminal *terminal, { height = rect.bottom - rect.top; width = rect.right - rect.left; - text_width = FRAME_PIXEL_TO_TEXT_WIDTH (f, width); - text_height = FRAME_PIXEL_TO_TEXT_HEIGHT (f, height); - /* rows = FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f, height); */ - /* columns = FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f, width); */ - - /* TODO: Clip size to the screen dimensions. */ - - /* Even if the number of character rows and columns - has not changed, the font size may have changed, - so we need to check the pixel dimensions as well. */ if (width != FRAME_PIXEL_WIDTH (f) - || height != FRAME_PIXEL_HEIGHT (f) - || text_width != FRAME_TEXT_WIDTH (f) - || text_height != FRAME_TEXT_HEIGHT (f)) + || height != FRAME_PIXEL_HEIGHT (f)) { - change_frame_size (f, text_width, text_height, 0, 1, 0, 1); + change_frame_size + (f, width, height, false, true, false); SET_FRAME_GARBAGED (f); cancel_mouse_face (f); f->win_gravity = NorthWestGravity; @@ -6267,17 +6244,15 @@ w32_new_font (struct frame *f, Lisp_Object font_object, int fontset) FRAME_CONFIG_SCROLL_BAR_COLS (f) * unit; } - /* Now make the frame display the given font. */ - if (FRAME_NATIVE_WINDOW (f) != 0) - { - /* Don't change the size of a tip frame; there's no point in - doing it because it's done in Fx_show_tip, and it leads to - problems because the tip frame has no widget. */ - if (!FRAME_TOOLTIP_P (f)) - adjust_frame_size (f, FRAME_COLS (f) * FRAME_COLUMN_WIDTH (f), - FRAME_LINES (f) * FRAME_LINE_HEIGHT (f), 3, - false, Qfont); - } + FRAME_TAB_BAR_HEIGHT (f) = FRAME_TAB_BAR_LINES (f) * FRAME_LINE_HEIGHT (f); + +/* Don't change the size of a tip frame; there's no point in + doing it because it's done in Fx_show_tip, and it leads to + problems because the tip frame has no widget. */ + if (FRAME_NATIVE_WINDOW (f) != 0 && !FRAME_TOOLTIP_P (f)) + adjust_frame_size + (f, FRAME_COLS (f) * FRAME_COLUMN_WIDTH (f), + FRAME_LINES (f) * FRAME_LINE_HEIGHT (f), 3, false, Qfont); /* X version sets font of input methods here also. */ @@ -6490,7 +6465,8 @@ w32fullscreen_hook (struct frame *f) ShowWindow (hwnd, SW_SHOWNORMAL); else if (f->want_fullscreen == FULLSCREEN_MAXIMIZED) { - if (prev_fsmode == FULLSCREEN_BOTH || prev_fsmode == FULLSCREEN_WIDTH + if (prev_fsmode == FULLSCREEN_BOTH + || prev_fsmode == FULLSCREEN_WIDTH || prev_fsmode == FULLSCREEN_HEIGHT) /* Make window normal since otherwise the subsequent maximization might fail in some cases. */ @@ -6499,52 +6475,31 @@ w32fullscreen_hook (struct frame *f) } else if (f->want_fullscreen == FULLSCREEN_BOTH) { - int menu_bar_height = GetSystemMetrics (SM_CYMENU); - - w32_fullscreen_rect (hwnd, f->want_fullscreen, - FRAME_NORMAL_PLACEMENT (f).rcNormalPosition, &rect); + w32_fullscreen_rect + (hwnd, f->want_fullscreen, + FRAME_NORMAL_PLACEMENT (f).rcNormalPosition, &rect); if (!FRAME_UNDECORATED (f)) SetWindowLong (hwnd, GWL_STYLE, dwStyle & ~WS_OVERLAPPEDWINDOW); SetWindowPos (hwnd, HWND_TOP, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, SWP_NOOWNERZORDER | SWP_FRAMECHANGED); change_frame_size - (f, FRAME_PIXEL_TO_TEXT_WIDTH (f, rect.right - rect.left), - FRAME_PIXEL_TO_TEXT_HEIGHT (f, (rect.bottom - rect.top - - menu_bar_height)), - 0, 1, 0, 1); + (f, rect.right - rect.left, rect.bottom - rect.top, + false, true, false); } else { ShowWindow (hwnd, SW_SHOWNORMAL); - w32_fullscreen_rect (hwnd, f->want_fullscreen, - FRAME_NORMAL_PLACEMENT (f).rcNormalPosition, &rect); + w32_fullscreen_rect + (hwnd, f->want_fullscreen, + FRAME_NORMAL_PLACEMENT (f).rcNormalPosition, &rect); SetWindowPos (hwnd, HWND_TOP, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, 0); - if (f->want_fullscreen == FULLSCREEN_WIDTH) - { - int border_width = GetSystemMetrics (SM_CXFRAME); - - change_frame_size - (f, (FRAME_PIXEL_TO_TEXT_WIDTH - (f, rect.right - rect.left - 2 * border_width)), - 0, 0, 1, 0, 1); - } - else - { - int border_height = GetSystemMetrics (SM_CYFRAME); - /* Won't work for wrapped menu bar. */ - int menu_bar_height = GetSystemMetrics (SM_CYMENU); - int title_height = GetSystemMetrics (SM_CYCAPTION); - - change_frame_size - (f, 0, (FRAME_PIXEL_TO_TEXT_HEIGHT - (f, rect.bottom - rect.top - 2 * border_height - - title_height - menu_bar_height)), - 0, 1, 0, 1); - } - } + change_frame_size + (f, rect.right - rect.left, rect.bottom - rect.top, + false, true, false); + } f->want_fullscreen = FULLSCREEN_NONE; unblock_input (); @@ -6559,16 +6514,14 @@ w32fullscreen_hook (struct frame *f) f->want_fullscreen |= FULLSCREEN_WAIT; } -/* Call this to change the size of frame F's native window. - If CHANGE_GRAVITY, change to top-left-corner window gravity - for this size change and subsequent size changes. - Otherwise we leave the window gravity unchanged. */ - +/* Change the size of frame F's Windows window to WIDTH and HEIGHT + pixels. If CHANGE_GRAVITY, change to top-left-corner window gravity + for this size change and subsequent size changes. Otherwise leave + the window gravity unchanged. */ static void w32_set_window_size (struct frame *f, bool change_gravity, - int width, int height, bool pixelwise) + int width, int height) { - int pixelwidth, pixelheight; Lisp_Object fullscreen = get_frame_param (f, Qfullscreen); RECT rect; MENUBARINFO info; @@ -6584,17 +6537,6 @@ w32_set_window_size (struct frame *f, bool change_gravity, GetMenuBarInfo (FRAME_W32_WINDOW (f), 0xFFFFFFFD, 0, &info); menu_bar_height = info.rcBar.bottom - info.rcBar.top; - if (pixelwise) - { - pixelwidth = FRAME_TEXT_TO_PIXEL_WIDTH (f, width); - pixelheight = FRAME_TEXT_TO_PIXEL_HEIGHT (f, height); - } - else - { - pixelwidth = FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, width); - pixelheight = FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f, height); - } - if (w32_add_wrapped_menu_bar_lines) { /* When the menu bar wraps sending a SetWindowPos shrinks the @@ -6610,15 +6552,15 @@ w32_set_window_size (struct frame *f, bool change_gravity, if ((default_menu_bar_height > 0) && (menu_bar_height > default_menu_bar_height) && ((menu_bar_height % default_menu_bar_height) == 0)) - pixelheight = pixelheight + menu_bar_height - default_menu_bar_height; + height = height + menu_bar_height - default_menu_bar_height; } f->win_gravity = NorthWestGravity; w32_wm_set_size_hint (f, (long) 0, false); rect.left = rect.top = 0; - rect.right = pixelwidth; - rect.bottom = pixelheight; + rect.right = width; + rect.bottom = height; AdjustWindowRect (&rect, f->output_data.w32->dwStyle, menu_bar_height > 0); @@ -6636,7 +6578,7 @@ w32_set_window_size (struct frame *f, bool change_gravity, { rect.left = window_rect.left; rect.right = window_rect.right; - pixelwidth = 0; + width = -1; } if (EQ (fullscreen, Qmaximized) || EQ (fullscreen, Qfullboth) @@ -6644,19 +6586,12 @@ w32_set_window_size (struct frame *f, bool change_gravity, { rect.top = window_rect.top; rect.bottom = window_rect.bottom; - pixelheight = 0; + height = -1; } } - if (pixelwidth > 0 || pixelheight > 0) + if (width > 0 || height > 0) { - frame_size_history_add - (f, Qx_set_window_size_1, width, height, - list2 (Fcons (make_fixnum (pixelwidth), - make_fixnum (pixelheight)), - Fcons (make_fixnum (rect.right - rect.left), - make_fixnum (rect.bottom - rect.top)))); - if (!FRAME_PARENT_FRAME (f)) my_set_window_pos (FRAME_W32_WINDOW (f), NULL, 0, 0, @@ -6670,12 +6605,7 @@ w32_set_window_size (struct frame *f, bool change_gravity, rect.bottom - rect.top, SWP_NOMOVE | SWP_NOACTIVATE); - change_frame_size (f, - ((pixelwidth == 0) - ? 0 : FRAME_PIXEL_TO_TEXT_WIDTH (f, pixelwidth)), - ((pixelheight == 0) - ? 0 : FRAME_PIXEL_TO_TEXT_HEIGHT (f, pixelheight)), - 0, 1, 0, 1); + change_frame_size (f, width, height, false, true, false); SET_FRAME_GARBAGED (f); /* If cursor was outside the new size, mark it as off. */ diff --git a/src/widget.c b/src/widget.c index 43f0307b4e0..dd43fd1c466 100644 --- a/src/widget.c +++ b/src/widget.c @@ -168,14 +168,6 @@ pixel_to_char_size (EmacsFrame ew, Dimension pixel_width, Dimension pixel_height *char_height = FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f, (int) pixel_height); } -static void -pixel_to_text_size (EmacsFrame ew, Dimension pixel_width, Dimension pixel_height, int *text_width, int *text_height) -{ - struct frame *f = ew->emacs_frame.frame; - *text_width = FRAME_PIXEL_TO_TEXT_WIDTH (f, (int) pixel_width); - *text_height = FRAME_PIXEL_TO_TEXT_HEIGHT (f, (int) pixel_height); -} - static void char_to_pixel_size (EmacsFrame ew, int char_width, int char_height, Dimension *pixel_width, Dimension *pixel_height) { @@ -257,27 +249,14 @@ set_frame_size (EmacsFrame ew) */ - /* Hairily merged geometry */ struct frame *f = ew->emacs_frame.frame; - int w = FRAME_COLS (f); - int h = FRAME_LINES (f); - Widget wmshell = get_wm_shell ((Widget) ew); - Dimension pixel_width, pixel_height; - /* Each Emacs shell is now independent and top-level. */ - - if (! XtIsSubclass (wmshell, shellWidgetClass)) emacs_abort (); - - char_to_pixel_size (ew, w, h, &pixel_width, &pixel_height); - ew->core.width = (frame_resize_pixelwise - ? FRAME_PIXEL_WIDTH (f) - : pixel_width); - ew->core.height = (frame_resize_pixelwise - ? FRAME_PIXEL_HEIGHT (f) - : pixel_height); - - frame_size_history_add - (f, Qset_frame_size, FRAME_TEXT_WIDTH (f), FRAME_TEXT_HEIGHT (f), - list2i (ew->core.width, ew->core.height)); + + ew->core.width = FRAME_PIXEL_WIDTH (f); + ew->core.height = FRAME_PIXEL_HEIGHT (f); + + if (CONSP (frame_size_history)) + frame_size_history_plain + (f, build_string ("set_frame_size")); } static void @@ -350,6 +329,13 @@ update_from_various_frame_slots (EmacsFrame ew) ew->emacs_frame.foreground_pixel = FRAME_FOREGROUND_PIXEL (f); ew->emacs_frame.cursor_color = x->cursor_pixel; ew->core.border_pixel = x->border_pixel; + + if (CONSP (frame_size_history)) + frame_size_history_extra + (f, build_string ("update_from_various_frame_slots"), + FRAME_PIXEL_WIDTH (f), FRAME_PIXEL_HEIGHT (f), + ew->core.width, ew->core.height, + f->new_width, f->new_height); } static void @@ -381,6 +367,7 @@ static void EmacsFrameRealize (Widget widget, XtValueMask *mask, XSetWindowAttributes *attrs) { EmacsFrame ew = (EmacsFrame) widget; + struct frame *f = ew->emacs_frame.frame; /* This used to contain SubstructureRedirectMask, but this turns out to be a problem with XIM on Solaris, and events from that mask @@ -394,6 +381,11 @@ EmacsFrameRealize (Widget widget, XtValueMask *mask, XSetWindowAttributes *attrs /* Some ConfigureNotify events does not end up in EmacsFrameResize so make sure we get them all. Seen with xfcwm4 for example. */ XtAddRawEventHandler (widget, StructureNotifyMask, False, resize_cb, NULL); + + if (CONSP (frame_size_history)) + frame_size_history_plain + (f, build_string ("EmacsFrameRealize")); + update_wm_hints (ew); } @@ -408,18 +400,15 @@ EmacsFrameResize (Widget widget) { EmacsFrame ew = (EmacsFrame) widget; struct frame *f = ew->emacs_frame.frame; - int width, height; - - pixel_to_text_size (ew, ew->core.width, ew->core.height, &width, &height); - frame_size_history_add - (f, QEmacsFrameResize, width, height, - list5 (make_fixnum (ew->core.width), make_fixnum (ew->core.height), - make_fixnum (FRAME_TOP_MARGIN_HEIGHT (f)), - make_fixnum (FRAME_SCROLL_BAR_AREA_HEIGHT (f)), - make_fixnum (2 * FRAME_INTERNAL_BORDER_WIDTH (f)))); + if (CONSP (frame_size_history)) + frame_size_history_extra + (f, build_string ("EmacsFrameResize"), + FRAME_PIXEL_WIDTH (f), FRAME_PIXEL_HEIGHT (f), + ew->core.width, ew->core.height, + f->new_width, f->new_height); - change_frame_size (f, width, height, 0, 1, 0, 1); + change_frame_size (f, ew->core.width, ew->core.height, false, true, false); update_wm_hints (ew); update_various_frame_slots (ew); @@ -463,9 +452,17 @@ EmacsFrameSetCharSize (Widget widget, int columns, int rows) EmacsFrame ew = (EmacsFrame) widget; struct frame *f = ew->emacs_frame.frame; + if (CONSP (frame_size_history)) + frame_size_history_extra + (f, build_string ("EmacsFrameSetCharSize"), + FRAME_PIXEL_WIDTH (f), FRAME_PIXEL_HEIGHT (f), + columns, rows, + f->new_width, f->new_height); + if (!frame_inhibit_resize (f, 0, Qfont) && !frame_inhibit_resize (f, 1, Qfont)) - x_set_window_size (f, 0, columns, rows, 0); + x_set_window_size (f, 0, columns * FRAME_COLUMN_WIDTH (f), + rows * FRAME_LINE_HEIGHT (f)); } diff --git a/src/xdisp.c b/src/xdisp.c index 7a89089958f..23b4ba5c39c 100644 --- a/src/xdisp.c +++ b/src/xdisp.c @@ -11860,7 +11860,7 @@ resize_mini_window (struct window *w, bool exact_p) int height, max_height; struct text_pos start; struct buffer *old_current_buffer = NULL; - int windows_height = FRAME_WINDOWS_HEIGHT (f); + int windows_height = FRAME_INNER_HEIGHT (f); if (current_buffer != XBUFFER (w->contents)) { @@ -13477,8 +13477,6 @@ PIXELWISE non-nil means return the height of the tab bar in pixels. */) static bool redisplay_tab_bar (struct frame *f) { - f->tab_bar_redisplayed = true; - struct window *w; struct it it; struct glyph_row *row; @@ -13492,6 +13490,8 @@ redisplay_tab_bar (struct frame *f) WINDOW_TOTAL_LINES (w) == 0)) return false; + f->tab_bar_redisplayed = true; + /* Set up an iterator for the tab-bar window. */ init_iterator (&it, w, -1, -1, w->desired_matrix->rows, TAB_BAR_FACE_ID); it.first_visible_x = 0; @@ -14402,21 +14402,13 @@ PIXELWISE non-nil means return the height of the tool bar in pixels. */) return make_fixnum (height); } +#ifndef HAVE_EXT_TOOL_BAR -/* Display the tool-bar of frame F. Value is true if tool-bar's - height should be changed. */ +/* Display the internal tool-bar of frame F. Value is true if + tool-bar's height should be changed. */ static bool redisplay_tool_bar (struct frame *f) { - f->tool_bar_redisplayed = true; -#ifdef HAVE_EXT_TOOL_BAR - - if (FRAME_EXTERNAL_TOOL_BAR (f)) - update_frame_tool_bar (f); - return false; - -#else /* ! (HAVE_EXT_TOOL_BAR) */ - struct window *w; struct it it; struct glyph_row *row; @@ -14430,6 +14422,8 @@ redisplay_tool_bar (struct frame *f) WINDOW_TOTAL_LINES (w) == 0)) return false; + f->tool_bar_redisplayed = true; + /* Set up an iterator for the tool-bar window. */ init_iterator (&it, w, -1, -1, w->desired_matrix->rows, TOOL_BAR_FACE_ID); it.first_visible_x = 0; @@ -14565,13 +14559,10 @@ redisplay_tool_bar (struct frame *f) } f->minimize_tool_bar_window_p = false; - return false; -#endif /* HAVE_EXT_TOOL_BAR */ + return false; } -#ifndef HAVE_EXT_TOOL_BAR - /* Get information about the tool-bar item which is displayed in GLYPH on frame F. Return in *PROP_IDX the index where tool-bar item properties start in F->tool_bar_items. Value is false if @@ -19334,7 +19325,7 @@ redisplay_window (Lisp_Object window, bool just_this_one_p) #ifdef HAVE_EXT_TOOL_BAR if (FRAME_EXTERNAL_TOOL_BAR (f)) - redisplay_tool_bar (f); + update_frame_tool_bar (f); #else if (WINDOWP (f->tool_bar_window) && (FRAME_TOOL_BAR_LINES (f) > 0 diff --git a/src/xfns.c b/src/xfns.c index f120653ee7b..2c95065d3ea 100644 --- a/src/xfns.c +++ b/src/xfns.c @@ -1563,7 +1563,6 @@ x_set_menu_bar_lines (struct frame *f, Lisp_Object value, Lisp_Object oldval) #else /* not USE_X_TOOLKIT && not USE_GTK */ FRAME_MENU_BAR_LINES (f) = nlines; FRAME_MENU_BAR_HEIGHT (f) = nlines * FRAME_LINE_HEIGHT (f); - adjust_frame_size (f, -1, -1, 2, true, Qx_set_menu_bar_lines); if (FRAME_X_WINDOW (f)) x_clear_under_internal_border (f); @@ -1577,6 +1576,8 @@ x_set_menu_bar_lines (struct frame *f, Lisp_Object value, Lisp_Object oldval) int width = FRAME_PIXEL_WIDTH (f); int y; + adjust_frame_size (f, -1, -1, 3, true, Qmenu_bar_lines); + /* height can be zero here. */ if (FRAME_X_WINDOW (f) && height > 0 && width > 0) { @@ -1637,7 +1638,7 @@ x_change_tab_bar_height (struct frame *f, int height) int unit = FRAME_LINE_HEIGHT (f); int old_height = FRAME_TAB_BAR_HEIGHT (f); int lines = (height + unit - 1) / unit; - Lisp_Object fullscreen; + Lisp_Object fullscreen = get_frame_param (f, Qfullscreen); /* Make sure we redisplay all windows in this frame. */ fset_redisplay (f); @@ -1645,16 +1646,8 @@ x_change_tab_bar_height (struct frame *f, int height) /* Recalculate tab bar and frame text sizes. */ FRAME_TAB_BAR_HEIGHT (f) = height; FRAME_TAB_BAR_LINES (f) = lines; - /* Store the `tab-bar-lines' and `height' frame parameters. */ store_frame_param (f, Qtab_bar_lines, make_fixnum (lines)); - store_frame_param (f, Qheight, make_fixnum (FRAME_LINES (f))); - - /* We also have to make sure that the internal border at the top of - the frame, below the menu bar or tab bar, is redrawn when the - tab bar disappears. This is so because the internal border is - below the tab bar if one is displayed, but is below the menu bar - if there isn't a tab bar. The tab bar draws into the area - below the menu bar. */ + if (FRAME_X_WINDOW (f) && FRAME_TAB_BAR_HEIGHT (f) == 0) { clear_frame (f); @@ -1664,25 +1657,21 @@ x_change_tab_bar_height (struct frame *f, int height) if ((height < old_height) && WINDOWP (f->tab_bar_window)) clear_glyph_matrix (XWINDOW (f->tab_bar_window)->current_matrix); - /* Recalculate tabbar height. */ - f->n_tab_bar_rows = 0; - if (old_height == 0 - && (!f->after_make_frame - || NILP (frame_inhibit_implied_resize) - || (CONSP (frame_inhibit_implied_resize) - && NILP (Fmemq (Qtab_bar_lines, frame_inhibit_implied_resize))))) - f->tab_bar_redisplayed = f->tab_bar_resized = false; - - adjust_frame_size (f, -1, -1, - ((!f->tab_bar_resized - && (NILP (fullscreen = - get_frame_param (f, Qfullscreen)) - || EQ (fullscreen, Qfullwidth))) ? 1 - : (old_height == 0 || height == 0) ? 2 - : 4), - false, Qtab_bar_lines); - - f->tab_bar_resized = f->tab_bar_redisplayed; + if (!f->tab_bar_resized) + { + /* As long as tab_bar_resized is false, effectively try to change + F's native height. */ + if (NILP (fullscreen) || EQ (fullscreen, Qfullwidth)) + adjust_frame_size (f, FRAME_TEXT_WIDTH (f), FRAME_TEXT_HEIGHT (f), + 1, false, Qtab_bar_lines); + else + adjust_frame_size (f, -1, -1, 4, false, Qtab_bar_lines); + + f->tab_bar_resized = f->tab_bar_redisplayed; + } + else + /* Any other change may leave the native size of F alone. */ + adjust_frame_size (f, -1, -1, 3, false, Qtab_bar_lines); /* adjust_frame_size might not have done anything, garbage frame here. */ @@ -1743,24 +1732,15 @@ x_change_tool_bar_height (struct frame *f, int height) int unit = FRAME_LINE_HEIGHT (f); int old_height = FRAME_TOOL_BAR_HEIGHT (f); int lines = (height + unit - 1) / unit; - Lisp_Object fullscreen; + Lisp_Object fullscreen = get_frame_param (f, Qfullscreen); /* Make sure we redisplay all windows in this frame. */ fset_redisplay (f); - /* Recalculate tool bar and frame text sizes. */ FRAME_TOOL_BAR_HEIGHT (f) = height; FRAME_TOOL_BAR_LINES (f) = lines; - /* Store the `tool-bar-lines' and `height' frame parameters. */ store_frame_param (f, Qtool_bar_lines, make_fixnum (lines)); - store_frame_param (f, Qheight, make_fixnum (FRAME_LINES (f))); - - /* We also have to make sure that the internal border at the top of - the frame, below the menu bar or tool bar, is redrawn when the - tool bar disappears. This is so because the internal border is - below the tool bar if one is displayed, but is below the menu bar - if there isn't a tool bar. The tool bar draws into the area - below the menu bar. */ + if (FRAME_X_WINDOW (f) && FRAME_TOOL_BAR_HEIGHT (f) == 0) { clear_frame (f); @@ -1770,25 +1750,21 @@ x_change_tool_bar_height (struct frame *f, int height) if ((height < old_height) && WINDOWP (f->tool_bar_window)) clear_glyph_matrix (XWINDOW (f->tool_bar_window)->current_matrix); - /* Recalculate toolbar height. */ - f->n_tool_bar_rows = 0; - if (old_height == 0 - && (!f->after_make_frame - || NILP (frame_inhibit_implied_resize) - || (CONSP (frame_inhibit_implied_resize) - && NILP (Fmemq (Qtool_bar_lines, frame_inhibit_implied_resize))))) - f->tool_bar_redisplayed = f->tool_bar_resized = false; - - adjust_frame_size (f, -1, -1, - ((!f->tool_bar_resized - && (NILP (fullscreen = - get_frame_param (f, Qfullscreen)) - || EQ (fullscreen, Qfullwidth))) ? 1 - : (old_height == 0 || height == 0) ? 2 - : 4), - false, Qtool_bar_lines); - - f->tool_bar_resized = f->tool_bar_redisplayed; + if (!f->tool_bar_resized) + { + /* As long as tool_bar_resized is false, effectively try to change + F's native height. */ + if (NILP (fullscreen) || EQ (fullscreen, Qfullwidth)) + adjust_frame_size (f, FRAME_TEXT_WIDTH (f), FRAME_TEXT_HEIGHT (f), + 1, false, Qtool_bar_lines); + else + adjust_frame_size (f, -1, -1, 4, false, Qtool_bar_lines); + + f->tool_bar_resized = f->tool_bar_redisplayed; + } + else + /* Any other change may leave the native size of F alone. */ + adjust_frame_size (f, -1, -1, 3, false, Qtool_bar_lines); /* adjust_frame_size might not have done anything, garbage frame here. */ @@ -3687,7 +3663,6 @@ This function is an internal primitive--use `make-frame' instead. */) struct x_display_info *dpyinfo = NULL; Lisp_Object parent, parent_frame; struct kboard *kb; - int x_width = 0, x_height = 0; parms = Fcopy_alist (parms); @@ -3999,18 +3974,6 @@ This function is an internal primitive--use `make-frame' instead. */) init_iterator with a null face cache, which should not happen. */ init_frame_faces (f); - /* We have to call adjust_frame_size here since otherwise - x_set_tool_bar_lines will already work with the character sizes - installed by init_frame_faces while the frame's pixel size is still - calculated from a character size of 1 and we subsequently hit the - (height >= 0) assertion in window_box_height. - - The non-pixelwise code apparently worked around this because it - had one frame line vs one toolbar line which left us with a zero - root window height which was obviously wrong as well ... - - Also process `min-width' and `min-height' parameters right here - because `frame-windows-min-size' needs them. */ tem = gui_display_get_arg (dpyinfo, parms, Qmin_width, NULL, NULL, RES_TYPE_NUMBER); if (FIXNUMP (tem)) @@ -4019,6 +3982,7 @@ This function is an internal primitive--use `make-frame' instead. */) RES_TYPE_NUMBER); if (FIXNUMP (tem)) store_frame_param (f, Qmin_height, tem); + adjust_frame_size (f, FRAME_COLS (f) * FRAME_COLUMN_WIDTH (f), FRAME_LINES (f) * FRAME_LINE_HEIGHT (f), 5, true, Qx_create_frame_1); @@ -4055,8 +4019,7 @@ This function is an internal primitive--use `make-frame' instead. */) RES_TYPE_BOOLEAN); /* Compute the size of the X window. */ - window_prompting = gui_figure_window_size (f, parms, true, true, - &x_width, &x_height); + window_prompting = gui_figure_window_size (f, parms, true, true); tem = gui_display_get_arg (dpyinfo, parms, Qunsplittable, 0, 0, RES_TYPE_BOOLEAN); @@ -4140,11 +4103,6 @@ This function is an internal primitive--use `make-frame' instead. */) /* Consider frame official, now. */ f->can_set_window_size = true; - if (x_width > 0) - SET_FRAME_WIDTH (f, x_width); - if (x_height > 0) - SET_FRAME_HEIGHT (f, x_height); - /* Tell the server what size and position, etc, we want, and how badly we want them. This should be done after we have the menu bar so that its size can be taken into account. */ @@ -6291,10 +6249,8 @@ x_create_tip_frame (struct x_display_info *dpyinfo, Lisp_Object parms) struct frame *f; Lisp_Object frame; Lisp_Object name; - int width, height; ptrdiff_t count = SPECPDL_INDEX (); bool face_change_before = face_change; - int x_width = 0, x_height = 0; if (!dpyinfo->terminal->name) error ("Terminal is not live, can't create new frames on it"); @@ -6418,7 +6374,7 @@ x_create_tip_frame (struct x_display_info *dpyinfo, Lisp_Object parms) gui_default_parameter (f, parms, Qborder_width, make_fixnum (0), "borderWidth", "BorderWidth", RES_TYPE_NUMBER); - /* This defaults to 2 in order to match xterm. We recognize either + /* This defaults to 1 in order to match xterm. We recognize either internalBorderWidth or internalBorder (which is what xterm calls it). */ if (NILP (Fassq (Qinternal_border_width, parms))) @@ -6466,7 +6422,7 @@ x_create_tip_frame (struct x_display_info *dpyinfo, Lisp_Object parms) "inhibitDoubleBuffering", "InhibitDoubleBuffering", RES_TYPE_BOOLEAN); - gui_figure_window_size (f, parms, false, false, &x_width, &x_height); + gui_figure_window_size (f, parms, false, false); { XSetWindowAttributes attrs; @@ -6518,15 +6474,6 @@ x_create_tip_frame (struct x_display_info *dpyinfo, Lisp_Object parms) gui_default_parameter (f, parms, Qalpha, Qnil, "alpha", "Alpha", RES_TYPE_NUMBER); - /* Dimensions, especially FRAME_LINES (f), must be done via change_frame_size. - Change will not be effected unless different from the current - FRAME_LINES (f). */ - width = FRAME_COLS (f); - height = FRAME_LINES (f); - SET_FRAME_COLS (f, 0); - SET_FRAME_LINES (f, 0); - change_frame_size (f, width, height, true, false, false, false); - /* Add `tooltip' frame parameter's default value. */ if (NILP (Fframe_parameter (frame, Qtooltip))) { @@ -6588,6 +6535,8 @@ x_create_tip_frame (struct x_display_info *dpyinfo, Lisp_Object parms) visible won't work. */ Vframe_list = Fcons (frame, Vframe_list); f->can_set_window_size = true; + adjust_frame_size (f, FRAME_TEXT_WIDTH (f), FRAME_TEXT_HEIGHT (f), + 0, true, Qtip_frame); /* Setting attributes of faces of the tooltip frame from resources and similar will set face_change, which leads to the clearing of diff --git a/src/xmenu.c b/src/xmenu.c index a83fffbf1ce..a6762236bc4 100644 --- a/src/xmenu.c +++ b/src/xmenu.c @@ -641,7 +641,7 @@ update_frame_menubar (struct frame *f) lw_refigure_widget (x->column_widget, True); /* Force the pane widget to resize itself. */ - adjust_frame_size (f, -1, -1, 2, false, Qupdate_frame_menubar); + adjust_frame_size (f, -1, -1, 2, false, Qmenu_bar_lines); unblock_input (); #endif /* USE_GTK */ } @@ -1044,6 +1044,7 @@ free_frame_menubar (struct frame *f) /* Motif automatically shrinks the frame in lw_destroy_all_widgets. If we want to preserve the old height, calculate it now so we can restore it below. */ + int old_width = FRAME_TEXT_WIDTH (f); int old_height = FRAME_TEXT_HEIGHT (f) + FRAME_MENUBAR_HEIGHT (f); #endif @@ -1077,26 +1078,43 @@ free_frame_menubar (struct frame *f) lw_destroy_all_widgets ((LWLIB_ID) f->output_data.x->id); f->output_data.x->menubar_widget = NULL; + /* When double-buffering is enabled and the frame shall not be + resized either because resizing is inhibited or the frame is + fullheight, some (usually harmless) display artifacts like a + doubled mode line may show up. Sometimes the configuration + gets messed up in a more serious fashion though and you may + have to resize the frame to get it back in a normal state. */ if (f->output_data.x->widget) { #ifdef USE_MOTIF XtVaGetValues (f->output_data.x->widget, XtNx, &x1, XtNy, &y1, NULL); if (x1 == 0 && y1 == 0) XtVaSetValues (f->output_data.x->widget, XtNx, x0, XtNy, y0, NULL); - if (frame_inhibit_resize (f, false, Qmenu_bar_lines)) - adjust_frame_size (f, -1, old_height, 1, false, Qfree_frame_menubar_1); + /* When resizing is inhibited and a normal Motif frame is not + fullheight, we have to explicitly request its old sizes + here since otherwise turning off the menu bar will shrink + the frame but turning them on again will not resize it + back. For a fullheight frame we let the window manager + deal with this problem. */ + if (frame_inhibit_resize (f, false, Qmenu_bar_lines) + && !EQ (get_frame_param (f, Qfullscreen), Qfullheight)) + adjust_frame_size (f, old_width, old_height, 1, false, + Qmenu_bar_lines); else - adjust_frame_size (f, -1, -1, 2, false, Qfree_frame_menubar_1); + adjust_frame_size (f, -1, -1, 2, false, Qmenu_bar_lines); #else - adjust_frame_size (f, -1, -1, 2, false, Qfree_frame_menubar_1); + adjust_frame_size (f, -1, -1, 2, false, Qmenu_bar_lines); #endif /* USE_MOTIF */ } else { #ifdef USE_MOTIF if (WINDOWP (FRAME_ROOT_WINDOW (f)) - && frame_inhibit_resize (f, false, Qmenu_bar_lines)) - adjust_frame_size (f, -1, old_height, 1, false, Qfree_frame_menubar_2); + /* See comment above. */ + && frame_inhibit_resize (f, false, Qmenu_bar_lines) + && !EQ (get_frame_param (f, Qfullscreen), Qfullheight)) + adjust_frame_size (f, old_width, old_height, 1, false, + Qmenu_bar_lines); #endif } diff --git a/src/xterm.c b/src/xterm.c index 11de287aecc..5049f72ca63 100644 --- a/src/xterm.c +++ b/src/xterm.c @@ -7833,10 +7833,6 @@ x_net_wm_state (struct frame *f, Window window) break; } - frame_size_history_add - (f, Qx_net_wm_state, 0, 0, - list2 (get_frame_param (f, Qfullscreen), lval)); - store_frame_param (f, Qfullscreen, lval); /** store_frame_param (f, Qsticky, sticky ? Qt : Qnil); **/ } @@ -8167,19 +8163,29 @@ handle_one_xevent (struct x_display_info *dpyinfo, if (f && event->xproperty.atom == dpyinfo->Xatom_net_wm_state) { bool not_hidden = x_handle_net_wm_state (f, &event->xproperty); + if (not_hidden && FRAME_ICONIFIED_P (f)) { + if (CONSP (frame_size_history)) + frame_size_history_plain + (f, build_string ("PropertyNotify, not hidden & iconified")); + /* Gnome shell does not iconify us when C-z is pressed. It hides the frame. So if our state says we aren't hidden anymore, treat it as deiconified. */ SET_FRAME_VISIBLE (f, 1); SET_FRAME_ICONIFIED (f, false); + f->output_data.x->has_been_visible = true; inev.ie.kind = DEICONIFY_EVENT; XSETFRAME (inev.ie.frame_or_window, f); } - else if (! not_hidden && ! FRAME_ICONIFIED_P (f)) + else if (!not_hidden && !FRAME_ICONIFIED_P (f)) { + if (CONSP (frame_size_history)) + frame_size_history_plain + (f, build_string ("PropertyNotify, hidden & not iconified")); + SET_FRAME_VISIBLE (f, 0); SET_FRAME_ICONIFIED (f, true); inev.ie.kind = ICONIFY_EVENT; @@ -8357,10 +8363,17 @@ handle_one_xevent (struct x_display_info *dpyinfo, and that way, we know the window is not iconified now. */ if (visible || FRAME_ICONIFIED_P (f)) { + if (CONSP (frame_size_history)) + frame_size_history_plain + (f, build_string ("UnmapNotify, visible | iconified")); + SET_FRAME_ICONIFIED (f, true); - inev.ie.kind = ICONIFY_EVENT; + inev.ie.kind = ICONIFY_EVENT; XSETFRAME (inev.ie.frame_or_window, f); } + else if (CONSP (frame_size_history)) + frame_size_history_plain + (f, build_string ("UnmapNotify, not visible & not iconified")); } goto OTHER; @@ -8372,8 +8385,24 @@ handle_one_xevent (struct x_display_info *dpyinfo, if (f) { bool iconified = FRAME_ICONIFIED_P (f); - - /* Check if fullscreen was specified before we where mapped the + int value; + bool sticky; + bool not_hidden = x_get_current_wm_state (f, event->xmap.window, &value, &sticky); + + if (CONSP (frame_size_history)) + frame_size_history_extra + (f, + iconified + ? (not_hidden + ? build_string ("MapNotify, not hidden & iconified") + : build_string ("MapNotify, hidden & iconified")) + : (not_hidden + ? build_string ("MapNotify, not hidden & not iconified") + : build_string ("MapNotify, hidden & not iconified")), + FRAME_PIXEL_WIDTH (f), FRAME_PIXEL_HEIGHT (f), + -1, -1, f->new_width, f->new_height); + + /* Check if fullscreen was specified before we where mapped the first time, i.e. from the command line. */ if (!f->output_data.x->has_been_visible) { @@ -8974,7 +9003,16 @@ handle_one_xevent (struct x_display_info *dpyinfo, || !(configureEvent.xconfigure.width <= 1 && configureEvent.xconfigure.height <= 1))) { - block_input (); + + if (CONSP (frame_size_history)) + frame_size_history_extra + (f, build_string ("ConfigureNotify"), + FRAME_PIXEL_WIDTH (f), FRAME_PIXEL_HEIGHT (f), + configureEvent.xconfigure.width, + configureEvent.xconfigure.height, + f->new_width, f->new_height); + + block_input (); if (FRAME_X_DOUBLE_BUFFERED_P (f)) font_drop_xrender_surfaces (f); unblock_input (); @@ -9015,24 +9053,28 @@ handle_one_xevent (struct x_display_info *dpyinfo, #ifndef USE_X_TOOLKIT #ifndef USE_GTK - int width = - FRAME_PIXEL_TO_TEXT_WIDTH (f, configureEvent.xconfigure.width); - int height = - FRAME_PIXEL_TO_TEXT_HEIGHT (f, configureEvent.xconfigure.height); + int width = configureEvent.xconfigure.width; + int height = configureEvent.xconfigure.height; + + if (CONSP (frame_size_history)) + frame_size_history_extra + (f, build_string ("ConfigureNotify"), + FRAME_PIXEL_WIDTH (f), FRAME_PIXEL_HEIGHT (f), + width, height, f->new_width, f->new_height); - /* In the toolkit version, change_frame_size + /* In the toolkit version, change_frame_size is called by the code that handles resizing of the EmacsFrame widget. */ /* Even if the number of character rows and columns has not changed, the font size may have changed, so we need to check the pixel dimensions as well. */ - if (width != FRAME_TEXT_WIDTH (f) - || height != FRAME_TEXT_HEIGHT (f) - || configureEvent.xconfigure.width != FRAME_PIXEL_WIDTH (f) - || configureEvent.xconfigure.height != FRAME_PIXEL_HEIGHT (f)) + if (width != FRAME_PIXEL_WIDTH (f) + || height != FRAME_PIXEL_HEIGHT (f) + || (delayed_size_change + && (width != f->new_width || height != f->new_height))) { - change_frame_size (f, width, height, false, true, false, true); + change_frame_size (f, width, height, false, true, false); x_clear_under_internal_border (f); SET_FRAME_GARBAGED (f); cancel_mouse_face (f); @@ -10217,11 +10259,6 @@ x_new_font (struct frame *f, Lisp_Object font_object, int fontset) { struct font *font = XFONT_OBJECT (font_object); int unit, font_ascent, font_descent; -#ifndef USE_X_TOOLKIT - int old_menu_bar_height = FRAME_MENU_BAR_HEIGHT (f); - int old_tab_bar_height = FRAME_TAB_BAR_HEIGHT (f); - Lisp_Object fullscreen; -#endif if (fontset < 0) fontset = fontset_from_font (font_object); @@ -10239,8 +10276,9 @@ x_new_font (struct frame *f, Lisp_Object font_object, int fontset) #ifndef USE_X_TOOLKIT FRAME_MENU_BAR_HEIGHT (f) = FRAME_MENU_BAR_LINES (f) * FRAME_LINE_HEIGHT (f); - FRAME_TAB_BAR_HEIGHT (f) = FRAME_TAB_BAR_LINES (f) * FRAME_LINE_HEIGHT (f); #endif + /* We could use a more elaborate calculation here. */ + FRAME_TAB_BAR_HEIGHT (f) = FRAME_TAB_BAR_LINES (f) * FRAME_LINE_HEIGHT (f); /* Compute character columns occupied by scrollbar. @@ -10253,34 +10291,14 @@ x_new_font (struct frame *f, Lisp_Object font_object, int fontset) else FRAME_CONFIG_SCROLL_BAR_COLS (f) = (14 + unit - 1) / unit; - if (FRAME_X_WINDOW (f) != 0) - { - /* Don't change the size of a tip frame; there's no point in - doing it because it's done in Fx_show_tip, and it leads to - problems because the tip frame has no widget. */ - if (!FRAME_TOOLTIP_P (f)) - { - adjust_frame_size (f, FRAME_COLS (f) * FRAME_COLUMN_WIDTH (f), - FRAME_LINES (f) * FRAME_LINE_HEIGHT (f), 3, - false, Qfont); -#ifndef USE_X_TOOLKIT - if ((FRAME_MENU_BAR_HEIGHT (f) != old_menu_bar_height - || FRAME_TAB_BAR_HEIGHT (f) != old_tab_bar_height) - && !f->after_make_frame - && (EQ (frame_inhibit_implied_resize, Qt) - || (CONSP (frame_inhibit_implied_resize) - && NILP (Fmemq (Qfont, frame_inhibit_implied_resize)))) - && (NILP (fullscreen = get_frame_param (f, Qfullscreen)) - || EQ (fullscreen, Qfullwidth))) - /* If the menu/tab bar height changes, try to keep text height - constant. */ - adjust_frame_size - (f, -1, FRAME_TEXT_HEIGHT (f) + FRAME_MENU_BAR_HEIGHT (f) - + FRAME_TAB_BAR_HEIGHT (f) - - old_menu_bar_height - old_tab_bar_height, 1, false, Qfont); -#endif /* USE_X_TOOLKIT */ - } - } + + /* Don't change the size of a tip frame; there's no point in doing it + because it's done in Fx_show_tip, and it leads to problems because + the tip frame has no widget. */ + if (FRAME_X_WINDOW (f) != 0 && !FRAME_TOOLTIP_P (f)) + adjust_frame_size + (f, FRAME_COLS (f) * FRAME_COLUMN_WIDTH (f), + FRAME_LINES (f) * FRAME_LINE_HEIGHT (f), 3, false, Qfont); #ifdef HAVE_X_I18N if (FRAME_XIC (f) @@ -11164,10 +11182,6 @@ x_handle_net_wm_state (struct frame *f, const XPropertyEvent *event) break; } - frame_size_history_add - (f, Qx_handle_net_wm_state, 0, 0, - list2 (get_frame_param (f, Qfullscreen), lval)); - store_frame_param (f, Qfullscreen, lval); store_frame_param (f, Qsticky, sticky ? Qt : Qnil); @@ -11222,9 +11236,6 @@ x_check_fullscreen (struct frame *f) emacs_abort (); } - frame_size_history_add - (f, Qx_check_fullscreen, width, height, Qnil); - x_wm_set_size_hint (f, 0, false); XResizeWindow (FRAME_X_DISPLAY (f), FRAME_OUTER_WINDOW (f), @@ -11234,8 +11245,7 @@ x_check_fullscreen (struct frame *f) x_wait_for_event (f, ConfigureNotify); else { - change_frame_size (f, width, height - FRAME_MENUBAR_HEIGHT (f), - false, true, false, true); + change_frame_size (f, width, height, false, true, false); x_sync (f); } } @@ -11389,57 +11399,12 @@ static void x_set_window_size_1 (struct frame *f, bool change_gravity, int width, int height) { - int pixelwidth = FRAME_TEXT_TO_PIXEL_WIDTH (f, width); - int pixelheight = FRAME_TEXT_TO_PIXEL_HEIGHT (f, height); - int old_width = FRAME_PIXEL_WIDTH (f); - int old_height = FRAME_PIXEL_HEIGHT (f); - Lisp_Object fullscreen = get_frame_param (f, Qfullscreen); - if (change_gravity) f->win_gravity = NorthWestGravity; x_wm_set_size_hint (f, 0, false); - /* When the frame is fullheight and we only want to change the width - or it is fullwidth and we only want to change the height we should - be able to preserve the fullscreen property. However, due to the - fact that we have to send a resize request anyway, the window - manager will abolish it. At least the respective size should - remain unchanged but giving the frame back its normal size will - be broken ... */ - if (EQ (fullscreen, Qfullwidth) && width == FRAME_TEXT_WIDTH (f)) - { - frame_size_history_add - (f, Qx_set_window_size_1, width, height, - list2i (old_height, pixelheight + FRAME_MENUBAR_HEIGHT (f))); - - XResizeWindow (FRAME_X_DISPLAY (f), FRAME_OUTER_WINDOW (f), - old_width, pixelheight + FRAME_MENUBAR_HEIGHT (f)); - } - else if (EQ (fullscreen, Qfullheight) && height == FRAME_TEXT_HEIGHT (f)) - { - frame_size_history_add - (f, Qx_set_window_size_2, width, height, - list2i (old_width, pixelwidth)); - - XResizeWindow (FRAME_X_DISPLAY (f), FRAME_OUTER_WINDOW (f), - pixelwidth, old_height); - } - - else - { - frame_size_history_add - (f, Qx_set_window_size_3, width, height, - list3i (pixelwidth + FRAME_TOOLBAR_WIDTH (f), - (pixelheight + FRAME_TOOLBAR_HEIGHT (f) - + FRAME_MENUBAR_HEIGHT (f)), - FRAME_MENUBAR_HEIGHT (f))); - - XResizeWindow (FRAME_X_DISPLAY (f), FRAME_OUTER_WINDOW (f), - pixelwidth, pixelheight + FRAME_MENUBAR_HEIGHT (f)); - fullscreen = Qnil; - } - - + XResizeWindow (FRAME_X_DISPLAY (f), FRAME_OUTER_WINDOW (f), + width, height + FRAME_MENUBAR_HEIGHT (f)); /* We've set {FRAME,PIXEL}_{WIDTH,HEIGHT} to the values we hope to receive in the ConfigureNotify event; if we get what we asked @@ -11468,66 +11433,42 @@ x_set_window_size_1 (struct frame *f, bool change_gravity, { x_wait_for_event (f, ConfigureNotify); - if (!NILP (fullscreen)) - /* Try to restore fullscreen state. */ - { - store_frame_param (f, Qfullscreen, fullscreen); - gui_set_fullscreen (f, fullscreen, fullscreen); - } + if (CONSP (frame_size_history)) + frame_size_history_extra + (f, build_string ("x_set_window_size_1, visible"), + FRAME_PIXEL_WIDTH (f), FRAME_PIXEL_HEIGHT (f), width, height, + f->new_width, f->new_height); } else { - change_frame_size (f, width, height, false, true, false, true); + if (CONSP (frame_size_history)) + frame_size_history_extra + (f, build_string ("x_set_window_size_1, invisible"), + FRAME_PIXEL_WIDTH (f), FRAME_PIXEL_HEIGHT (f), width, height, + f->new_width, f->new_height); + + /* Call adjust_frame_size right away as with GTK. It might be + tempting to clear out f->new_width and f->new_height here. */ + adjust_frame_size (f, FRAME_PIXEL_TO_TEXT_WIDTH (f, width), + FRAME_PIXEL_TO_TEXT_HEIGHT (f, height), + 5, 0, Qx_set_window_size_1); + x_sync (f); } } -/* Call this to change the size of frame F's x-window. - If CHANGE_GRAVITY, change to top-left-corner window gravity - for this size change and subsequent size changes. - Otherwise we leave the window gravity unchanged. */ +/* Change the size of frame F's X window to WIDTH and HEIGHT pixels. If + CHANGE_GRAVITY, change to top-left-corner window gravity for this + size change and subsequent size changes. Otherwise we leave the + window gravity unchanged. */ void x_set_window_size (struct frame *f, bool change_gravity, - int width, int height, bool pixelwise) + int width, int height) { block_input (); - /* The following breaks our calculations. If it's really needed, - think of something else. */ -#if false - if (!FRAME_TOOLTIP_P (f)) - { - int text_width, text_height; - - /* When the frame is maximized/fullscreen or running under for - example Xmonad, x_set_window_size_1 will be a no-op. - In that case, the right thing to do is extend rows/width to - the current frame size. We do that first if x_set_window_size_1 - turns out to not be a no-op (there is no way to know). - The size will be adjusted again if the frame gets a - ConfigureNotify event as a result of x_set_window_size. */ - int pixelh = FRAME_PIXEL_HEIGHT (f); -#ifdef USE_X_TOOLKIT - /* The menu bar is not part of text lines. The tool bar - is however. */ - pixelh -= FRAME_MENUBAR_HEIGHT (f); -#endif - text_width = FRAME_PIXEL_TO_TEXT_WIDTH (f, FRAME_PIXEL_WIDTH (f)); - text_height = FRAME_PIXEL_TO_TEXT_HEIGHT (f, pixelh); - - change_frame_size (f, text_width, text_height, false, true, false, true); - } -#endif - - /* Pixelize width and height, if necessary. */ - if (! pixelwise) - { - width = width * FRAME_COLUMN_WIDTH (f); - height = height * FRAME_LINE_HEIGHT (f); - } - #ifdef USE_GTK if (FRAME_GTK_WIDGET (f)) xg_frame_set_char_size (f, width, height); @@ -11880,6 +11821,11 @@ x_make_frame_visible (struct frame *f) poll_for_input_1 (); poll_suppress_count = old_poll_suppress_count; #endif + + if (CONSP (frame_size_history)) + frame_size_history_plain + (f, build_string ("x_make_frame_visible")); + if (! FRAME_VISIBLE_P (f)) x_wait_for_event (f, MapNotify); } @@ -11937,6 +11883,10 @@ x_make_frame_invisible (struct frame *f) SET_FRAME_VISIBLE (f, 0); SET_FRAME_ICONIFIED (f, false); + if (CONSP (frame_size_history)) + frame_size_history_plain + (f, build_string ("x_make_frame_invisible")); + unblock_input (); } diff --git a/src/xterm.h b/src/xterm.h index ebc42b7dd55..de6ea50385d 100644 --- a/src/xterm.h +++ b/src/xterm.h @@ -1079,7 +1079,7 @@ extern bool x_had_errors_p (Display *); extern void x_uncatch_errors (void); extern void x_uncatch_errors_after_check (void); extern void x_clear_errors (Display *); -extern void x_set_window_size (struct frame *f, bool, int, int, bool); +extern void x_set_window_size (struct frame *f, bool, int, int); extern void x_make_frame_visible (struct frame *f); extern void x_make_frame_invisible (struct frame *f); extern void x_iconify_frame (struct frame *f); -- cgit v1.2.3 From bd5c7404195e45f11946b4e0933a1f8b697d8b87 Mon Sep 17 00:00:00 2001 From: Gregory Heytings Date: Sat, 15 May 2021 20:15:59 +0000 Subject: Fix key recording bug when an input method is activated * lisp/international/quail.el (quail-add-unread-command-events): New function. (quail-start-translation, quail-start-conversion) (quail-update-translation, quail-next-translation) (quail-prev-translation, quail-next-translation-block) (quail-prev-translation-block, quail-minibuffer-message): Use 'quail-add-unread-command-events' (and partly revert commit 03e3440dbb). (Bug#48042) * lisp/subr.el (inhibit--record-char): Now obsolete. * lisp/term/xterm.el (xterm--init): New function, with most of the code of former 'terminal-init-xterm'. (terminal-init-xterm): Clear the lossage after terminal initialization (see Bug#44908). (xterm--read-event-for-query): Do not use 'inhibit--record-char' anymore (revert commit 3e6525d69f). * src/keyboard.c (syms_of_keyboard): Remove 'inhibit--record-char' (partly revert 03e3440dbb). (record_char, syms_of_keyboard_for_pdumper): Do not use 'inhibit_record_char anymore'. --- lisp/international/quail.el | 72 ++++++++++++++++++++++----------------------- lisp/subr.el | 6 ++++ lisp/term/xterm.el | 20 +++++++++---- src/keyboard.c | 13 -------- 4 files changed, 55 insertions(+), 56 deletions(-) (limited to 'src/keyboard.c') diff --git a/lisp/international/quail.el b/lisp/international/quail.el index fff06deee88..33851f09a13 100644 --- a/lisp/international/quail.el +++ b/lisp/international/quail.el @@ -1368,6 +1368,27 @@ If STR has `advice' text property, append the following special event: (delete-region (overlay-start quail-overlay) (overlay-end quail-overlay)))) +(defun quail-add-unread-command-events (key &optional reset) + "Add KEY to `unread-command-events', ensuring that it is not recorded. +If KEY is a character, it is prepended to `unread-command-events' as +a cons cell of the form (no-record . KEY). +If KEY is a vector of events, the events in the vector are prepended +to `unread-command-events', after converting each event to a cons cell +of the form (no-record . EVENT). +Quail puts keys back in `unread-command-events' to be handled again, +and when it does this these keys have already been recorded in the +recent keys and in the keyboard macro being defined, which means that +recording them again creates duplicates. +When RESET is non-nil, the events in `unread-command-events' are first +discarded." + (if reset (setq unread-command-events nil)) + (setq unread-command-events + (if (characterp key) + (cons (cons 'no-record key) unread-command-events) + (append (mapcan (lambda (e) (list (cons 'no-record e))) + (append key nil)) + unread-command-events)))) + (defun quail-start-translation (key) "Start translation of the typed character KEY by the current Quail package. Return the input string." @@ -1385,13 +1406,11 @@ Return the input string." ;; (generated-events nil) ;FIXME: What is this? (input-method-function nil) (modified-p (buffer-modified-p)) - last-command-event last-command this-command inhibit-record) + last-command-event last-command this-command) (setq quail-current-key "" quail-current-str "" quail-translating t) - (if key - (setq unread-command-events (cons key unread-command-events) - inhibit-record t)) + (if key (quail-add-unread-command-events key)) (while quail-translating (set-buffer-modified-p modified-p) (quail-show-guidance) @@ -1400,13 +1419,8 @@ Return the input string." (or input-method-previous-message "") quail-current-str quail-guidance-str))) - ;; We inhibit record_char only for the first key, - ;; because it was already recorded before read_char - ;; called quail-input-method. - (inhibit--record-char inhibit-record) (keyseq (read-key-sequence prompt nil nil t)) (cmd (lookup-key (quail-translation-keymap) keyseq))) - (setq inhibit-record nil) (if (if key (and (commandp cmd) (not (eq cmd 'quail-other-command))) (eq cmd 'quail-self-insert-command)) @@ -1420,9 +1434,7 @@ Return the input string." (quail-error (message "%s" (cdr err)) (beep)))) ;; KEYSEQ is not defined in the translation keymap. ;; Let's return the event(s) to the caller. - (setq unread-command-events - (append (this-single-command-raw-keys) - unread-command-events)) + (quail-add-unread-command-events (this-single-command-raw-keys)) (setq quail-translating nil)))) (quail-delete-region) quail-current-str) @@ -1450,15 +1462,13 @@ Return the input string." ;; (generated-events nil) ;FIXME: What is this? (input-method-function nil) (modified-p (buffer-modified-p)) - last-command-event last-command this-command inhibit-record) + last-command-event last-command this-command) (setq quail-current-key "" quail-current-str "" quail-translating t quail-converting t quail-conversion-str "") - (if key - (setq unread-command-events (cons key unread-command-events) - inhibit-record t)) + (if key (quail-add-unread-command-events key)) (while quail-converting (set-buffer-modified-p modified-p) (or quail-translating @@ -1474,13 +1484,8 @@ Return the input string." quail-conversion-str quail-current-str quail-guidance-str))) - ;; We inhibit record_char only for the first key, - ;; because it was already recorded before read_char - ;; called quail-input-method. - (inhibit--record-char inhibit-record) (keyseq (read-key-sequence prompt nil nil t)) (cmd (lookup-key (quail-conversion-keymap) keyseq))) - (setq inhibit-record nil) (if (if key (commandp cmd) (eq cmd 'quail-self-insert-command)) (progn (setq last-command-event (aref keyseq (1- (length keyseq))) @@ -1503,9 +1508,7 @@ Return the input string." (setq quail-converting nil))))) ;; KEYSEQ is not defined in the conversion keymap. ;; Let's return the event(s) to the caller. - (setq unread-command-events - (append (this-single-command-raw-keys) - unread-command-events)) + (quail-add-unread-command-events (this-single-command-raw-keys)) (setq quail-converting nil)))) (setq quail-translating nil) (if (overlay-start quail-conv-overlay) @@ -1551,9 +1554,8 @@ with more keys." (or input-method-exit-on-first-char (while (> len control-flag) (setq len (1- len)) - (setq unread-command-events - (cons (aref quail-current-key len) - unread-command-events)))))) + (quail-add-unread-command-events + (aref quail-current-key len)))))) ((null control-flag) (unless quail-current-str (setq quail-current-str @@ -1799,8 +1801,7 @@ sequence counting from the head." (setcar indices (1+ (car indices))) (quail-update-current-translations) (quail-update-translation nil))) - (setq unread-command-events - (cons last-command-event unread-command-events)) + (quail-add-unread-command-events last-command-event) (quail-terminate-translation))) (defun quail-prev-translation () @@ -1814,8 +1815,7 @@ sequence counting from the head." (setcar indices (1- (car indices))) (quail-update-current-translations) (quail-update-translation nil))) - (setq unread-command-events - (cons last-command-event unread-command-events)) + (quail-add-unread-command-events last-command-event) (quail-terminate-translation))) (defun quail-next-translation-block () @@ -1830,8 +1830,7 @@ sequence counting from the head." (setcar indices (+ (nth 2 indices) offset)) (quail-update-current-translations) (quail-update-translation nil))) - (setq unread-command-events - (cons last-command-event unread-command-events)) + (quail-add-unread-command-events last-command-event) (quail-terminate-translation))) (defun quail-prev-translation-block () @@ -1850,8 +1849,7 @@ sequence counting from the head." (setcar indices (+ (nth 1 indices) offset)) (quail-update-current-translations))) (quail-update-translation nil))) - (setq unread-command-events - (cons last-command-event unread-command-events)) + (quail-add-unread-command-events last-command-event) (quail-terminate-translation))) (defun quail-abort-translation () @@ -2006,8 +2004,8 @@ Remaining args are for FUNC." (sit-for 1000000) (delete-region point-max (point-max)) (when quit-flag - (setq quit-flag nil - unread-command-events '(7))))) + (setq quit-flag nil) + (quail-add-unread-command-events 7 t)))) (defun quail-show-guidance () "Display a guidance for Quail input method in some window. diff --git a/lisp/subr.el b/lisp/subr.el index 82c2d221a68..78507a552c1 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -1757,6 +1757,12 @@ be a list of the form returned by `event-start' and `event-end'." (make-obsolete-variable 'load-dangerous-libraries "no longer used." "27.1") +(defvar inhibit--record-char nil + "Obsolete variable. +This was used internally by quail.el and keyboard.c in Emacs 27. +It does nothing in Emacs 28.") +(make-obsolete-variable 'inhibit--record-char nil "28.1") + ;; We can't actually make `values' obsolete, because that will result ;; in warnings when using `values' in let-bindings. ;;(make-obsolete-variable 'values "no longer used" "28.1") diff --git a/lisp/term/xterm.el b/lisp/term/xterm.el index eeaf805930b..8bcae37afe4 100644 --- a/lisp/term/xterm.el +++ b/lisp/term/xterm.el @@ -770,8 +770,7 @@ Can be nil to mean \"no timeout\".") By not redisplaying right away for xterm queries, we can avoid unsightly flashing during initialization. Give up and redisplay anyway if we've been waiting a little while." - (let ((start-time (current-time)) - (inhibit--record-char t)) + (let ((start-time (current-time))) (or (let ((inhibit-redisplay t)) (read-event nil nil xterm-query-redisplay-timeout)) (read-event nil nil @@ -839,8 +838,8 @@ We run the first FUNCTION whose STRING matches the input events." basemap (make-composed-keymap map (keymap-parent basemap)))) -(defun terminal-init-xterm () - "Terminal initialization function for xterm." +(defun xterm--init () + "Initialize the terminal for xterm." ;; rxvt terminals sometimes set the TERM variable to "xterm", but ;; rxvt's keybindings are incompatible with xterm's. It is ;; better in that case to use rxvt's initialization function. @@ -882,9 +881,18 @@ We run the first FUNCTION whose STRING matches the input events." ;; support it just ignore the sequence. (xterm--init-bracketed-paste-mode) ;; We likewise unconditionally enable support for focus tracking. - (xterm--init-focus-tracking) + (xterm--init-focus-tracking)) - (run-hooks 'terminal-init-xterm-hook)) +(defun terminal-init-xterm () + "Terminal initialization function for xterm." + (unwind-protect + (progn + (xterm--init) + ;; If the terminal initialization completed without errors, clear + ;; the lossage to discard the responses of the terminal emulator + ;; during initialization; otherwise they appear in the recent keys. + (clear-this-command-keys)) + (run-hooks 'terminal-init-xterm-hook))) (defun xterm--init-modify-other-keys () "Terminal initialization for xterm's modifyOtherKeys support." diff --git a/src/keyboard.c b/src/keyboard.c index 47b5e590245..c855d45afab 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -3233,10 +3233,6 @@ help_char_p (Lisp_Object c) static void record_char (Lisp_Object c) { - /* quail.el binds this to avoid recording keys twice. */ - if (inhibit_record_char) - return; - int recorded = 0; if (CONSP (c) && (EQ (XCAR (c), Qhelp_echo) || EQ (XCAR (c), Qmouse_movement))) @@ -12343,13 +12339,6 @@ If nil, Emacs crashes immediately in response to fatal signals. */); Vwhile_no_input_ignore_events, doc: /* Ignored events from while-no-input. */); - DEFVAR_BOOL ("inhibit--record-char", - inhibit_record_char, - doc: /* If non-nil, don't record input events. -This inhibits recording input events for the purposes of keyboard -macros, dribble file, and `recent-keys'. -Internal use only. */); - pdumper_do_now_and_after_load (syms_of_keyboard_for_pdumper); } @@ -12383,8 +12372,6 @@ syms_of_keyboard_for_pdumper (void) /* Create the initial keyboard. Qt means 'unset'. */ eassert (initial_kboard == NULL); initial_kboard = allocate_kboard (Qt); - - inhibit_record_char = false; } void -- cgit v1.2.3 From 6e2d3bce087d30a535b1f01715d7820576ffe390 Mon Sep 17 00:00:00 2001 From: Alan Mackenzie Date: Mon, 31 May 2021 10:33:10 +0000 Subject: Correct mouse handling when window origin changes between down and up events Do this by using frame relative positions rather than window relative ones, which gave rise to spurious drag events when the origin of the window changed between the mouse down and up events. This fixes bug #48409. * keyboard.c (frame_relative_event_pos): New static variable. (make_lispy_event): Record frame relative position of down event. When the up event is in the same position, "move" this event into the window of the down event when this window (typically a mini-window) is no longer under the mouse. Call make_lispy_position a second time to generate this changed event. (syms_of_keyboard): Declare Qwindow_edges. static_pro frame_relative_event_pos. --- src/keyboard.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 51 insertions(+), 13 deletions(-) (limited to 'src/keyboard.c') diff --git a/src/keyboard.c b/src/keyboard.c index c855d45afab..4433cfa4193 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -5018,6 +5018,10 @@ static short const internal_border_parts[] = { static Lisp_Object button_down_location; +/* A cons recording the original frame-relative x and y coordinates of + the down mouse event. */ +static Lisp_Object frame_relative_event_pos; + /* Information about the most recent up-going button event: Which button, what location, and what time. */ @@ -5669,6 +5673,7 @@ make_lispy_event (struct input_event *event) double_click_count = 1; button_down_time = event->timestamp; *start_pos_ptr = Fcopy_alist (position); + frame_relative_event_pos = Fcons (event->x, event->y); ignore_mouse_drag_p = false; } @@ -5691,20 +5696,12 @@ make_lispy_event (struct input_event *event) ignore_mouse_drag_p = false; else { - Lisp_Object new_down, down; intmax_t xdiff = double_click_fuzz, ydiff = double_click_fuzz; - /* The third element of every position - should be the (x,y) pair. */ - down = Fcar (Fcdr (Fcdr (start_pos))); - new_down = Fcar (Fcdr (Fcdr (position))); - - if (CONSP (down) - && FIXNUMP (XCAR (down)) && FIXNUMP (XCDR (down))) - { - xdiff = XFIXNUM (XCAR (new_down)) - XFIXNUM (XCAR (down)); - ydiff = XFIXNUM (XCDR (new_down)) - XFIXNUM (XCDR (down)); - } + xdiff = XFIXNUM (event->x) + - XFIXNUM (XCAR (frame_relative_event_pos)); + ydiff = XFIXNUM (event->y) + - XFIXNUM (XCDR (frame_relative_event_pos)); if (! (0 < double_click_fuzz && - double_click_fuzz < xdiff @@ -5721,12 +5718,51 @@ make_lispy_event (struct input_event *event) a click. But mouse-drag-region completely ignores this case and it hasn't caused any real problem, so it's probably OK to ignore it as well. */ - && EQ (Fcar (Fcdr (start_pos)), Fcar (Fcdr (position))))) + && (EQ (Fcar (Fcdr (start_pos)), + Fcar (Fcdr (position))) /* Same buffer pos */ + || !EQ (Fcar (start_pos), + Fcar (position))))) /* Different window */ { /* Mouse has moved enough. */ button_down_time = 0; click_or_drag_modifier = drag_modifier; } + else if (((!EQ (Fcar (start_pos), Fcar (position))) + || (!EQ (Fcar (Fcdr (start_pos)), + Fcar (Fcdr (position))))) + /* Was the down event in a window body? */ + && FIXNUMP (Fcar (Fcdr (start_pos))) + && WINDOW_LIVE_P (Fcar (start_pos)) + && Ffboundp (Qwindow_edges)) + /* If the window (etc.) at the mouse position has + changed between the down event and the up event, + we assume there's been a redisplay between the + two events, and we pretend the mouse is still in + the old window to prevent a spurious drag event + being generated. */ + { + Lisp_Object edges + = call4 (Qwindow_edges, Fcar (start_pos), Qt, Qnil, Qt); + int new_x = XFIXNUM (Fcar (frame_relative_event_pos)); + int new_y = XFIXNUM (Fcdr (frame_relative_event_pos)); + + /* If the up-event is outside the down-event's + window, use coordinates that are within it. */ + if (new_x < XFIXNUM (Fcar (edges))) + new_x = XFIXNUM (Fcar (edges)); + else if (new_x >= XFIXNUM (Fcar (Fcdr (Fcdr (edges))))) + new_x = XFIXNUM (Fcar (Fcdr (Fcdr (edges)))) - 1; + if (new_y < XFIXNUM (Fcar (Fcdr (edges)))) + new_y = XFIXNUM (Fcar (Fcdr (edges))); + else if (new_y + >= XFIXNUM (Fcar (Fcdr (Fcdr (Fcdr (edges)))))) + new_y = XFIXNUM (Fcar (Fcdr (Fcdr (Fcdr (edges))))) - 1; + + position = make_lispy_position + (XFRAME (event->frame_or_window), + make_fixnum (new_x), make_fixnum (new_y), + event->timestamp); + } } /* Don't check is_double; treat this as multiple if the @@ -11645,6 +11681,7 @@ syms_of_keyboard (void) DEFSYM (Qmake_frame_visible, "make-frame-visible"); DEFSYM (Qselect_window, "select-window"); DEFSYM (Qselection_request, "selection-request"); + DEFSYM (Qwindow_edges, "window-edges"); { int i; @@ -11661,6 +11698,7 @@ syms_of_keyboard (void) button_down_location = make_nil_vector (5); staticpro (&button_down_location); + staticpro (&frame_relative_event_pos); mouse_syms = make_nil_vector (5); staticpro (&mouse_syms); wheel_syms = make_nil_vector (ARRAYELTS (lispy_wheel_names)); -- cgit v1.2.3 From 63e9a4b1e1fe99462ec97b2145b91898fa5b4085 Mon Sep 17 00:00:00 2001 From: Glenn Morris Date: Mon, 31 May 2021 08:40:26 -0700 Subject: * src/keyboard.c (make_lispy_event): Fix previous. --- src/keyboard.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/keyboard.c') diff --git a/src/keyboard.c b/src/keyboard.c index 4433cfa4193..bddbb793a50 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -5733,7 +5733,7 @@ make_lispy_event (struct input_event *event) /* Was the down event in a window body? */ && FIXNUMP (Fcar (Fcdr (start_pos))) && WINDOW_LIVE_P (Fcar (start_pos)) - && Ffboundp (Qwindow_edges)) + && !NILP (Ffboundp (Qwindow_edges))) /* If the window (etc.) at the mouse position has changed between the down event and the up event, we assume there's been a redisplay between the -- cgit v1.2.3 From d08067d3620654fbe2352d42de8152ea20159cc4 Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Thu, 3 Jun 2021 09:29:55 +0200 Subject: Cross-reference the message/error control variables * src/keyboard.c (syms_of_keyboard): Mention set-message-function in the command-error-function doc string... * src/xdisp.c (syms_of_xdisp): ... and vice versa (bug#13752). --- src/keyboard.c | 5 ++++- src/xdisp.c | 6 ++++-- 2 files changed, 8 insertions(+), 3 deletions(-) (limited to 'src/keyboard.c') diff --git a/src/keyboard.c b/src/keyboard.c index bddbb793a50..d2facc23644 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -12303,7 +12303,10 @@ Called with three arguments: - the error data, a list of the form (SIGNALED-CONDITION . SIGNAL-DATA) such as what `condition-case' would bind its variable to, - the context (a string which normally goes at the start of the message), -- the Lisp function within which the error was signaled. */); +- the Lisp function within which the error was signaled. + +Also see `set-message-function' (which controls how non-error messages +are displayed). */); Vcommand_error_function = intern ("command-error-default-function"); DEFVAR_LISP ("enable-disabled-menus-and-buttons", diff --git a/src/xdisp.c b/src/xdisp.c index 0a95aa32f94..0e8672961ae 100644 --- a/src/xdisp.c +++ b/src/xdisp.c @@ -35639,8 +35639,10 @@ as usual. If the function returns a string, the returned string is displayed in the echo area. If this function returns any other non-nil value, this means that the message was already handled, and the original message text will not be displayed in the echo area. -See also `clear-message-function' that can be used to clear the -message displayed by this function. */); + +Also see `clear-message-function' (which can be used to clear the +message displayed by this function), and `command-error-function' +(which controls how error messages are displayed). */); Vset_message_function = Qnil; DEFVAR_LISP ("clear-message-function", Vclear_message_function, -- cgit v1.2.3 From 515eb6989575dc1d8e8f996ec65494e637f24ffe Mon Sep 17 00:00:00 2001 From: Max Mikhanosha Date: Sat, 5 Jun 2021 16:57:43 +0300 Subject: Support terminal emulators that encode the Meta modifier as 8th bit See discussion starting at https://lists.gnu.org/archive/html/emacs-devel/2021-06/msg00034.html for the details. * src/keyboard.c (read_decoded_event_from_main_queue): For raw-text encoed input, if Meta bit is encoded, apply the Meta modifier to single-byte characters that have the 0x80 bit set. For input encoded otherwise, if the Meta bit is encoded, remove the 0x80 bit after decoding the characters. (tty_read_avail_input): Reset the 0x80 bit only if Meta bit is not encoded. (Fset_input_meta_mode): Support 'encoded' as the value of META. (Fset_input_mode): Document 'encoded' for META. (Fcurrent_input_mode): Support and document 'encoded' as the value of META. (syms_of_keyboard): DEFSYM 'encoded'. --- src/keyboard.c | 53 +++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 43 insertions(+), 10 deletions(-) (limited to 'src/keyboard.c') diff --git a/src/keyboard.c b/src/keyboard.c index d2facc23644..c63826e34d1 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -2254,8 +2254,17 @@ read_decoded_event_from_main_queue (struct timespec *end_time, { int i; if (meta_key != 2) - for (i = 0; i < n; i++) - events[i] = make_fixnum (XFIXNUM (events[i]) & ~0x80); + { + for (i = 0; i < n; i++) + { + int c = XFIXNUM (events[i]); + int modifier = + (meta_key == 3 && c < 0x100 && (c & 0x80)) + ? meta_modifier + : 0; + events[i] = make_fixnum ((c & ~0x80) | modifier; + } + } } else { @@ -2264,7 +2273,7 @@ read_decoded_event_from_main_queue (struct timespec *end_time, int i; for (i = 0; i < n; i++) src[i] = XFIXNUM (events[i]); - if (meta_key != 2) + if (meta_key < 2) /* input-meta-mode is t or nil */ for (i = 0; i < n; i++) src[i] &= ~0x80; coding->destination = dest; @@ -2282,7 +2291,18 @@ read_decoded_event_from_main_queue (struct timespec *end_time, eassert (coding->carryover_bytes == 0); n = 0; while (n < coding->produced_char) - events[n++] = make_fixnum (string_char_advance (&p)); + { + int c = string_char_advance (&p); + if (meta_key == 3) + { + int modifier + = (c < 0x100 && (c & 0x80) + ? meta_modifier + : 0); + c = (c & ~0x80) | modifier; + } + events[n++] = make_fixnum (c); + } } } } @@ -7068,7 +7088,7 @@ tty_read_avail_input (struct terminal *terminal, buf.modifiers = 0; if (tty->meta_key == 1 && (cbuf[i] & 0x80)) buf.modifiers = meta_modifier; - if (tty->meta_key != 2) + if (tty->meta_key < 2) cbuf[i] &= ~0x80; buf.code = cbuf[i]; @@ -11075,7 +11095,10 @@ See also `current-input-mode'. */) DEFUN ("set-input-meta-mode", Fset_input_meta_mode, Sset_input_meta_mode, 1, 2, 0, doc: /* Enable or disable 8-bit input on TERMINAL. If META is t, Emacs will accept 8-bit input, and interpret the 8th -bit as the Meta modifier. +bit as the Meta modifier before it decodes the characters. + +If META is `encoded', Emacs will interpret the 8th bit of single-byte +characters after decoding the characters. If META is nil, Emacs will ignore the top bit, on the assumption it is parity. @@ -11104,6 +11127,8 @@ See also `current-input-mode'. */) new_meta = 0; else if (EQ (meta, Qt)) new_meta = 1; + else if (EQ (meta, Qencoded)) + new_meta = 3; else new_meta = 2; @@ -11166,6 +11191,8 @@ Second arg FLOW non-nil means use ^S/^Q flow control for output to terminal (no effect except in CBREAK mode). Third arg META t means accept 8-bit input (for a Meta key). META nil means ignore the top bit, on the assumption it is parity. + META `encoded' means accept 8-bit input and interpret Meta after + decoding the input characters. Otherwise, accept 8-bit input and don't use the top bit for Meta. Optional fourth arg QUIT if non-nil specifies character to use for quitting. See also `current-input-mode'. */) @@ -11186,9 +11213,12 @@ The value is a list of the form (INTERRUPT FLOW META QUIT), where nil, Emacs is using CBREAK mode. FLOW is non-nil if Emacs uses ^S/^Q flow control for output to the terminal; this does not apply if Emacs uses interrupt-driven input. - META is t if accepting 8-bit input with 8th bit as Meta flag. - META nil means ignoring the top bit, on the assumption it is parity. - META is neither t nor nil if accepting 8-bit input and using + META is t if accepting 8-bit unencoded input with 8th bit as Meta flag. + META is `encoded' if accepting 8-bit encoded input with 8th bit as + Meta flag which has to be interpreted after decoding the input. + META is nil if ignoring the top bit of input, on the assumption that + it is a parity bit. + META is neither t nor nil if accepting 8-bit input and using all 8 bits as the character code. QUIT is the character Emacs currently uses to quit. The elements of this list correspond to the arguments of @@ -11204,7 +11234,9 @@ The elements of this list correspond to the arguments of flow = FRAME_TTY (sf)->flow_control ? Qt : Qnil; meta = (FRAME_TTY (sf)->meta_key == 2 ? make_fixnum (0) - : (CURTTY ()->meta_key == 1 ? Qt : Qnil)); + : (CURTTY ()->meta_key == 1 + ? Qt + : (CURTTY ()->meta_key == 3 ? Qencoded : Qnil))); } else { @@ -11695,6 +11727,7 @@ syms_of_keyboard (void) } } DEFSYM (Qno_record, "no-record"); + DEFSYM (Qencoded, "encoded"); button_down_location = make_nil_vector (5); staticpro (&button_down_location); -- cgit v1.2.3 From c9424189fc85140e376812d9b4bc4e6420d64976 Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Sat, 5 Jun 2021 11:57:57 -0400 Subject: * src/keyboard.c (read_decoded_event_from_main_queue): Fix paren typo --- src/keyboard.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/keyboard.c') diff --git a/src/keyboard.c b/src/keyboard.c index c63826e34d1..051f2f8b38a 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -2262,7 +2262,7 @@ read_decoded_event_from_main_queue (struct timespec *end_time, (meta_key == 3 && c < 0x100 && (c & 0x80)) ? meta_modifier : 0; - events[i] = make_fixnum ((c & ~0x80) | modifier; + events[i] = make_fixnum ((c & ~0x80) | modifier); } } } -- cgit v1.2.3 From d4217b38d72be5b4b025260ff9839b51808f9f40 Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Thu, 15 Jul 2021 07:17:53 +0200 Subject: Clarify overriding-local-map doc string * src/keyboard.c (syms_of_keyboard): Clarify `overriding-local-map' vs. text properties/overlays (bug#16312). --- src/keyboard.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/keyboard.c') diff --git a/src/keyboard.c b/src/keyboard.c index 051f2f8b38a..6174a4aad92 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -12141,10 +12141,11 @@ terminal device. See Info node `(elisp)Multiple Terminals'. */); DEFVAR_LISP ("overriding-local-map", Voverriding_local_map, doc: /* Keymap that replaces (overrides) local keymaps. If this variable is non-nil, Emacs looks up key bindings in this -keymap INSTEAD OF the keymap char property, minor mode maps, and the -buffer's local map. Hence, the only active keymaps would be -`overriding-terminal-local-map', this keymap, and `global-keymap', in -order of precedence. */); +keymap INSTEAD OF `keymap' text properties, `local-map' and `keymap' +overlay properties, minor mode maps, and the buffer's local map. + +Hence, the only active keymaps would be `overriding-terminal-local-map', +this keymap, and `global-keymap', in order of precedence. */); Voverriding_local_map = Qnil; DEFVAR_LISP ("overriding-local-map-menu-flag", Voverriding_local_map_menu_flag, -- cgit v1.2.3 From 48dfaa734be15e22f2a30a8cac73353e4649ce0a Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Sun, 18 Jul 2021 18:18:03 +0200 Subject: Clarify event-convert-list doc string * src/keyboard.c (Fevent_convert_list): Clarify that the base type returned isn't always the same (bug#7631). --- src/keyboard.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/keyboard.c') diff --git a/src/keyboard.c b/src/keyboard.c index 6174a4aad92..77d6bbba623 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -6622,8 +6622,11 @@ DEFUN ("event-convert-list", Fevent_convert_list, Sevent_convert_list, 1, 1, 0, EVENT-DESC should contain one base event type (a character or symbol) and zero or more modifier names (control, meta, hyper, super, shift, alt, drag, down, double or triple). The base must be last. -The return value is an event type (a character or symbol) which -has the same base event type and all the specified modifiers. */) + +The return value is an event type (a character or symbol) which has +essentially the same base event type and all the specified modifiers. +(Some compatibility base types, like symbols that represent a +character, are not returned verbatim.) */) (Lisp_Object event_desc) { Lisp_Object base = Qnil; -- cgit v1.2.3 From 7edbcb3648e9d08a4ccc291f672f831b4f07eb5c Mon Sep 17 00:00:00 2001 From: Miha Rihtaršič Date: Tue, 20 Jul 2021 14:36:45 +0200 Subject: Quit minibuffers without aborting kmacros * doc/lispref/commands.texi (Quitting): Document `minibuffer-quit' (Recursive Editing): Document throwing of function values to `exit'. * doc/lispref/errors.texi (Standard Errors): Document `minibuffer-quit' * lisp/minibuffer.el (minibuffer-quit-recursive-edit): New function. * lisp/simple.el (minibuffer-error-function): Do not abort keyboard macro execution if is minibuffer-quit is signaled (bug#48603). * src/data.c (syms_of_data): New error symbol `minibuffer-quit' * src/keyboard.c (recursive_edit_1): Implement throwing of function values to `exit`. In that case, the function will be called without arguments before returning from the command loop. (cmd_error): (Fcommand_error_default_function): Do not abort keyboard macro execution if minibuffer-quit is signaled. (command_loop_2): New argument HANDLERS. * src/macros.c (Fexecute_kbd_macro): Use command_loop_2 instead of command_loop_1. * src/minibuf.c (Fabort_minibuffers): Use it. --- doc/lispref/commands.texi | 14 +++++++++++--- doc/lispref/errors.texi | 9 +++++++-- etc/NEWS | 9 +++++++++ lisp/minibuffer.el | 9 +++++++++ lisp/simple.el | 6 ++++-- src/data.c | 2 ++ src/keyboard.c | 45 +++++++++++++++++++++++++++++++++------------ src/lisp.h | 2 +- src/macros.c | 2 +- src/minibuf.c | 2 +- 10 files changed, 78 insertions(+), 22 deletions(-) (limited to 'src/keyboard.c') diff --git a/doc/lispref/commands.texi b/doc/lispref/commands.texi index f30419c3ee7..b4a8b733a0b 100644 --- a/doc/lispref/commands.texi +++ b/doc/lispref/commands.texi @@ -3381,6 +3381,12 @@ nil)}. This is the same thing that quitting does. (See @code{signal} in @ref{Errors}.) @end deffn + To quit without aborting a keyboard macro definition or execution, +you can signal the @code{minibuffer-quit} condition. This has almost +the same effect as the @code{quit} condition except that the error +handling in the command loop handles it without exiting keyboard macro +definition or execution. + You can specify a character other than @kbd{C-g} to use for quitting. See the function @code{set-input-mode} in @ref{Input Modes}. @@ -3565,12 +3571,14 @@ commands. @code{recursive-edit}. This function contains the command loop; it also contains a call to @code{catch} with tag @code{exit}, which makes it possible to exit the recursive editing level by throwing to @code{exit} -(@pxref{Catch and Throw}). If you throw a value other than @code{t}, -then @code{recursive-edit} returns normally to the function that called -it. The command @kbd{C-M-c} (@code{exit-recursive-edit}) does this. +(@pxref{Catch and Throw}). If you throw a @code{nil} value, then +@code{recursive-edit} returns normally to the function that called it. +The command @kbd{C-M-c} (@code{exit-recursive-edit}) does this. Throwing a @code{t} value causes @code{recursive-edit} to quit, so that control returns to the command loop one level up. This is called @dfn{aborting}, and is done by @kbd{C-]} (@code{abort-recursive-edit}). +You can also throw a function value. In that case, +@code{recursive-edit} will call it without arguments before returning. Most applications should not use recursive editing, except as part of using the minibuffer. Usually it is more convenient for the user if you diff --git a/doc/lispref/errors.texi b/doc/lispref/errors.texi index fb393b951f1..f848218e267 100644 --- a/doc/lispref/errors.texi +++ b/doc/lispref/errors.texi @@ -20,8 +20,9 @@ the errors in accessing files have the condition @code{file-error}. If we do not say here that a certain error symbol has additional error conditions, that means it has none. - As a special exception, the error symbol @code{quit} does not have the -condition @code{error}, because quitting is not considered an error. + As a special exception, the error symbols @code{quit} and +@code{minibuffer-quit} don't have the condition @code{error}, because +quitting is not considered an error. Most of these error symbols are defined in C (mainly @file{data.c}), but some are defined in Lisp. For example, the file @file{userlock.el} @@ -40,6 +41,10 @@ The message is @samp{error}. @xref{Errors}. @item quit The message is @samp{Quit}. @xref{Quitting}. +@item minibuffer-quit +The message is @samp{Quit}. This is a subcategory of @code{quit}. +@xref{Quitting}. + @item args-out-of-range The message is @samp{Args out of range}. This happens when trying to access an element beyond the range of a sequence, buffer, or other diff --git a/etc/NEWS b/etc/NEWS index 953c952d05d..df09d81bcfe 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -2682,6 +2682,15 @@ also keep the type information of their arguments. Use the --- *** New face 'perl-heredoc', used for heredoc elements. ++++ +** A function can now be thrown to the 'exit' label in addition to t or nil. +The command loop will call it with zero arguments before returning. + ++++ +** New error symbol 'minibuffer-quit'. +Signaling it has almost the same effect as 'quit' except that it +doesn't cause keyboard macro termination. + --- *** The command 'cperl-set-style' offers the new value "PBP". This value customizes Emacs to use the style recommended in Damian diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el index 813ce14c59b..1578ab8e1ea 100644 --- a/lisp/minibuffer.el +++ b/lisp/minibuffer.el @@ -2328,6 +2328,15 @@ variables.") (setq deactivate-mark nil) (throw 'exit nil)) +(defun minibuffer-quit-recursive-edit () + "Quit the command that requested this recursive edit without error. +Like `abort-recursive-edit' without aborting keyboard macro +execution." + ;; See Info node `(elisp)Recursive Editing' for an explanation of + ;; throwing a function to `exit'. + (throw 'exit (lambda () + (signal 'minibuffer-quit nil)))) + (defun self-insert-and-exit () "Terminate minibuffer input." (interactive) diff --git a/lisp/simple.el b/lisp/simple.el index 5741c24eb7b..1a49fe24252 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -2879,8 +2879,10 @@ Go to the history element by the absolute history position HIST-POS." The same as `command-error-default-function' but display error messages at the end of the minibuffer using `minibuffer-message' to not obscure the minibuffer contents." - (discard-input) - (ding) + (if (memq 'minibuffer-quit (get (car data) 'error-conditions)) + (ding t) + (discard-input) + (ding)) (let ((string (error-message-string data))) ;; If we know from where the error was signaled, show it in ;; *Messages*. diff --git a/src/data.c b/src/data.c index 9adfafacaa5..ffca7e75355 100644 --- a/src/data.c +++ b/src/data.c @@ -3901,6 +3901,7 @@ syms_of_data (void) DEFSYM (Qerror, "error"); DEFSYM (Quser_error, "user-error"); DEFSYM (Qquit, "quit"); + DEFSYM (Qminibuffer_quit, "minibuffer-quit"); DEFSYM (Qwrong_length_argument, "wrong-length-argument"); DEFSYM (Qwrong_type_argument, "wrong-type-argument"); DEFSYM (Qargs_out_of_range, "args-out-of-range"); @@ -3973,6 +3974,7 @@ syms_of_data (void) Fput (sym, Qerror_message, build_pure_c_string (msg)) PUT_ERROR (Qquit, Qnil, "Quit"); + PUT_ERROR (Qminibuffer_quit, pure_cons (Qquit, Qnil), "Quit"); PUT_ERROR (Quser_error, error_tail, ""); PUT_ERROR (Qwrong_length_argument, error_tail, "Wrong length argument"); diff --git a/src/keyboard.c b/src/keyboard.c index 77d6bbba623..db934686594 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -725,6 +725,9 @@ recursive_edit_1 (void) if (STRINGP (val)) xsignal1 (Qerror, val); + if (FUNCTIONP (val)) + call0 (val); + return unbind_to (count, Qnil); } @@ -921,6 +924,7 @@ static Lisp_Object cmd_error (Lisp_Object data) { Lisp_Object old_level, old_length; + Lisp_Object conditions; char macroerror[sizeof "After..kbd macro iterations: " + INT_STRLEN_BOUND (EMACS_INT)]; @@ -940,10 +944,15 @@ cmd_error (Lisp_Object data) else *macroerror = 0; + conditions = Fget (XCAR (data), Qerror_conditions); + if (NILP (Fmemq (Qminibuffer_quit, conditions))) + { + Vexecuting_kbd_macro = Qnil; + executing_kbd_macro = Qnil; + } + Vstandard_output = Qt; Vstandard_input = Qt; - Vexecuting_kbd_macro = Qnil; - executing_kbd_macro = Qnil; kset_prefix_arg (current_kboard, Qnil); kset_last_prefix_arg (current_kboard, Qnil); cancel_echoing (); @@ -998,6 +1007,7 @@ Default value of `command-error-function'. */) (Lisp_Object data, Lisp_Object context, Lisp_Object signal) { struct frame *sf = SELECTED_FRAME (); + Lisp_Object conditions; CHECK_STRING (context); @@ -1024,17 +1034,27 @@ Default value of `command-error-function'. */) } else { + conditions = Fget (XCAR (data), Qerror_conditions); + clear_message (1, 0); - Fdiscard_input (); message_log_maybe_newline (); - bitch_at_user (); + + if (!NILP (Fmemq (Qminibuffer_quit, conditions))) + { + Fding (Qt); + } + else + { + Fdiscard_input (); + bitch_at_user (); + } print_error_message (data, Qt, SSDATA (context), signal); } return Qnil; } -static Lisp_Object command_loop_2 (Lisp_Object); +static Lisp_Object command_loop_1 (void); static Lisp_Object top_level_1 (Lisp_Object); /* Entry to editor-command-loop. @@ -1062,7 +1082,7 @@ command_loop (void) if (command_loop_level > 0 || minibuf_level > 0) { Lisp_Object val; - val = internal_catch (Qexit, command_loop_2, Qnil); + val = internal_catch (Qexit, command_loop_2, Qerror); executing_kbd_macro = Qnil; return val; } @@ -1070,7 +1090,7 @@ command_loop (void) while (1) { internal_catch (Qtop_level, top_level_1, Qnil); - internal_catch (Qtop_level, command_loop_2, Qnil); + internal_catch (Qtop_level, command_loop_2, Qerror); executing_kbd_macro = Qnil; /* End of file in -batch run causes exit here. */ @@ -1083,15 +1103,16 @@ command_loop (void) editing loop, and reenter the editing loop. When there is an error, cmd_error runs and returns a non-nil value to us. A value of nil means that command_loop_1 itself - returned due to end of file (or end of kbd macro). */ + returned due to end of file (or end of kbd macro). HANDLERS is a + list of condition names, passed to internal_condition_case. */ -static Lisp_Object -command_loop_2 (Lisp_Object ignore) +Lisp_Object +command_loop_2 (Lisp_Object handlers) { register Lisp_Object val; do - val = internal_condition_case (command_loop_1, Qerror, cmd_error); + val = internal_condition_case (command_loop_1, handlers, cmd_error); while (!NILP (val)); return Qnil; @@ -1234,7 +1255,7 @@ static int read_key_sequence (Lisp_Object *, Lisp_Object, bool, bool, bool, bool); static void adjust_point_for_property (ptrdiff_t, bool); -Lisp_Object +static Lisp_Object command_loop_1 (void) { modiff_count prev_modiff = 0; diff --git a/src/lisp.h b/src/lisp.h index 1795b9d811b..b3f1dc16b13 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -4417,7 +4417,7 @@ extern bool detect_input_pending_ignore_squeezables (void); extern bool detect_input_pending_run_timers (bool); extern void safe_run_hooks (Lisp_Object); extern void cmd_error_internal (Lisp_Object, const char *); -extern Lisp_Object command_loop_1 (void); +extern Lisp_Object command_loop_2 (Lisp_Object); extern Lisp_Object read_menu_command (void); extern Lisp_Object recursive_edit_1 (void); extern void record_auto_save (void); diff --git a/src/macros.c b/src/macros.c index 60d0766a754..0752a5bb6f6 100644 --- a/src/macros.c +++ b/src/macros.c @@ -324,7 +324,7 @@ buffer before the macro is executed. */) break; } - command_loop_1 (); + command_loop_2 (list1 (Qminibuffer_quit)); executing_kbd_macro_iterations = ++success_count; diff --git a/src/minibuf.c b/src/minibuf.c index 1b842b77211..0f4349e70b8 100644 --- a/src/minibuf.c +++ b/src/minibuf.c @@ -496,7 +496,7 @@ confirm the aborting of the current minibuffer and all contained ones. */) } } else - Fthrow (Qexit, Qt); + CALLN (Ffuncall, intern ("minibuffer-quit-recursive-edit")); return Qnil; } -- cgit v1.2.3 From da4b3973deb5eb271d79568092ad25560b65dbf8 Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Wed, 21 Jul 2021 16:53:54 +0200 Subject: Make `C-g' after `M-x' not give a backtrace unless required * src/eval.c (signal_quit_p): New function. (maybe_call_debugger): React to all `quit' signals (bug#49675). * src/keyboard.c (cmd_error_internal, menu_item_eval_property_1): Ditto. --- src/eval.c | 14 +++++++++++++- src/keyboard.c | 4 ++-- src/lisp.h | 1 + 3 files changed, 16 insertions(+), 3 deletions(-) (limited to 'src/keyboard.c') diff --git a/src/eval.c b/src/eval.c index b76ced79d61..ddf7e703fc2 100644 --- a/src/eval.c +++ b/src/eval.c @@ -2026,6 +2026,18 @@ skip_debugger (Lisp_Object conditions, Lisp_Object data) return 0; } +/* Say whether SIGNAL is a `quit' symbol (or inherits from it). */ +bool +signal_quit_p (Lisp_Object signal) +{ + Lisp_Object list; + + return EQ (signal, Qquit) + || (Fsymbolp (signal) + && CONSP (list = Fget (signal, Qerror_conditions)) + && Fmemq (Qquit, list)); +} + /* Call the debugger if calling it is currently enabled for CONDITIONS. SIG and DATA describe the signal. There are two ways to pass them: = SIG is the error symbol, and DATA is the rest of the data. @@ -2044,7 +2056,7 @@ maybe_call_debugger (Lisp_Object conditions, Lisp_Object sig, Lisp_Object data) ! input_blocked_p () && NILP (Vinhibit_debugger) /* Does user want to enter debugger for this kind of error? */ - && (EQ (sig, Qquit) + && (signal_quit_p (sig) ? debug_on_quit : wants_debugger (Vdebug_on_error, conditions)) && ! skip_debugger (conditions, combined_data) diff --git a/src/keyboard.c b/src/keyboard.c index db934686594..38118071a80 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -985,7 +985,7 @@ cmd_error_internal (Lisp_Object data, const char *context) { /* The immediate context is not interesting for Quits, since they are asynchronous. */ - if (EQ (XCAR (data), Qquit)) + if (signal_quit_p (XCAR (data))) Vsignaling_function = Qnil; Vquit_flag = Qnil; @@ -7634,7 +7634,7 @@ menu_item_eval_property_1 (Lisp_Object arg) { /* If we got a quit from within the menu computation, quit all the way out of it. This takes care of C-] in the debugger. */ - if (CONSP (arg) && EQ (XCAR (arg), Qquit)) + if (CONSP (arg) && signal_quit_p (XCAR (arg))) quit (); return Qnil; diff --git a/src/lisp.h b/src/lisp.h index b3f1dc16b13..80efd771139 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -4116,6 +4116,7 @@ extern Lisp_Object Vautoload_queue; extern Lisp_Object Vrun_hooks; extern Lisp_Object Vsignaling_function; extern Lisp_Object inhibit_lisp_code; +extern bool signal_quit_p (Lisp_Object); /* To run a normal hook, use the appropriate function from the list below. The calling convention: -- cgit v1.2.3 From 903ecd7bea7d8f99a7dc84150728219283d79bf0 Mon Sep 17 00:00:00 2001 From: Logan Perkins Date: Wed, 21 Jul 2021 17:56:20 +0200 Subject: Make input of multi-key inputs in different emacsclients more logical * src/keyboard.c (read_key_sequence): Don't continue the input of multi-key commands in one emacsclient in another (bug#39687). --- src/keyboard.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'src/keyboard.c') diff --git a/src/keyboard.c b/src/keyboard.c index 38118071a80..820229cf8fe 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -9619,17 +9619,23 @@ read_key_sequence (Lisp_Object *keybuf, Lisp_Object prompt, (interrupted_kboard, Fcons (make_lispy_switch_frame (frame), KVAR (interrupted_kboard, kbd_queue))); + mock_input = 0; + } + else + { + if (FIXNUMP (key) && XFIXNUM (key) != -2) + { + /* If interrupted while initializing terminal, we + need to replay the interrupting key. See + Bug#5095 and Bug#37782. */ + mock_input = 1; + keybuf[0] = key; + } + else + { + mock_input = 0; + } } - if (FIXNUMP (key) && XFIXNUM (key) != -2) - { - /* If interrupted while initializing terminal, we - need to replay the interrupting key. See - Bug#5095 and Bug#37782. */ - mock_input = 1; - keybuf[0] = key; - } - else - mock_input = 0; goto replay_entire_sequence; } } -- cgit v1.2.3 From 65dd00667ff060cf79fea4b49bfa4d8f7a16ee1f Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Fri, 13 Aug 2021 13:19:39 +0200 Subject: Fix problem where an error would change standard-output * src/keyboard.c (cmd_error): Don't set standard-output/standard-input (bug#30529). Instead bind them temporarily while handling the error. --- src/keyboard.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/keyboard.c') diff --git a/src/keyboard.c b/src/keyboard.c index 820229cf8fe..2e4c4e6aabf 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -924,6 +924,7 @@ static Lisp_Object cmd_error (Lisp_Object data) { Lisp_Object old_level, old_length; + ptrdiff_t count = SPECPDL_INDEX (); Lisp_Object conditions; char macroerror[sizeof "After..kbd macro iterations: " + INT_STRLEN_BOUND (EMACS_INT)]; @@ -951,8 +952,8 @@ cmd_error (Lisp_Object data) executing_kbd_macro = Qnil; } - Vstandard_output = Qt; - Vstandard_input = Qt; + specbind (Qstandard_output, Qt); + specbind (Qstandard_input, Qt); kset_prefix_arg (current_kboard, Qnil); kset_last_prefix_arg (current_kboard, Qnil); cancel_echoing (); @@ -969,6 +970,7 @@ cmd_error (Lisp_Object data) Vquit_flag = Qnil; Vinhibit_quit = Qnil; + unbind_to (count, Qnil); return make_fixnum (0); } -- cgit v1.2.3