From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.bugs Subject: bug#48674: Frames and minibuffer bug Date: Sun, 30 May 2021 13:58:30 +0000 Message-ID: References: <1e21b121-91c1-cbe9-d9ae-24915f163ae5@gmx.at> <89cc93a4-15b1-2d1c-095e-7a0b5f1683a1@gmx.at> <3dba4122-30e3-99a7-2326-263f3f7023cf@gmx.at> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="33702"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 48674@debbugs.gnu.org, Iris =?UTF-8?Q?Garc=C3=ADa?= To: martin rudalics Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun May 30 15:59:14 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lnLyE-0008en-9W for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 30 May 2021 15:59:14 +0200 Original-Received: from localhost ([::1]:33238 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lnLyD-0008Fv-BO for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 30 May 2021 09:59:13 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:57210) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lnLy3-0008Fm-7B for bug-gnu-emacs@gnu.org; Sun, 30 May 2021 09:59:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:48584) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lnLy3-0007vq-01 for bug-gnu-emacs@gnu.org; Sun, 30 May 2021 09:59:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1lnLy2-0005GY-W7 for bug-gnu-emacs@gnu.org; Sun, 30 May 2021 09:59:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Alan Mackenzie Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 30 May 2021 13:59:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 48674 X-GNU-PR-Package: emacs Original-Received: via spool by 48674-submit@debbugs.gnu.org id=B48674.162238312120197 (code B ref 48674); Sun, 30 May 2021 13:59:02 +0000 Original-Received: (at 48674) by debbugs.gnu.org; 30 May 2021 13:58:41 +0000 Original-Received: from localhost ([127.0.0.1]:60128 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lnLxh-0005Fg-As for submit@debbugs.gnu.org; Sun, 30 May 2021 09:58:41 -0400 Original-Received: from colin.muc.de ([193.149.48.1]:58232 helo=mail.muc.de) by debbugs.gnu.org with smtp (Exim 4.84_2) (envelope-from ) id 1lnLxe-0005FT-QM for 48674@debbugs.gnu.org; Sun, 30 May 2021 09:58:40 -0400 Original-Received: (qmail 41846 invoked by uid 3782); 30 May 2021 13:58:31 -0000 Original-Received: from acm.muc.de (p2e5d5a0f.dip0.t-ipconnect.de [46.93.90.15]) (using STARTTLS) by colin.muc.de (tmda-ofmipd) with ESMTP; Sun, 30 May 2021 15:58:31 +0200 Original-Received: (qmail 16437 invoked by uid 1000); 30 May 2021 13:58:30 -0000 Content-Disposition: inline In-Reply-To: X-Submission-Agent: TMDA/1.3.x (Ph3nix) X-Primary-Address: acm@muc.de X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:207618 Archived-At: Hello again, Martin. On Sat, May 29, 2021 at 17:00:04 +0000, Alan Mackenzie wrote: > On Sat, May 29, 2021 at 17:12:58 +0200, martin rudalics wrote: [ .... ] > > > Maybe the best workaround would be to create a new flag in struct > > > frame, which when set means "select mini-window if "possible" > > > when selecting this frame". "Possible" meaning there's an active > > > MB. (i) This flag would be set, somehow, by with-selected-frame > > > when moving away from F1. [ .... ] > I've been thinking about my proposed mechanism. There is no need for > with-selected-frame to set that new flag in struct frame. More simply, > do_switch_frame can set it whenever the old frame has the mini-window > selected. In the new frame it will check the flag and if appropriate > select the MW. Functions such as Fselect_window and > Fset_frame_selected_window which want to select a specific window would > clear the flag. > This mechanism could be implemented entirely in the C code, without > affecting any Lisp interfaces. [ .... ] > I think I'm going to discard yesterday's attempted patch, and write > another patch along the lines sketched above. This will likely take me > longer than just this evening. Here is that patch. Please tell me what you think of it. Thanks! diff --git a/src/frame.c b/src/frame.c index e3d65dd28f..623e4ba2cd 100644 --- a/src/frame.c +++ b/src/frame.c @@ -982,6 +982,7 @@ make_frame (bool mini_p) f->ns_transparent_titlebar = false; #endif #endif + f->select_mini_window_flag = false; /* This one should never be zero. */ f->change_stamp = 1; root_window = make_window (); @@ -1542,7 +1543,17 @@ do_switch_frame (Lisp_Object frame, int track, int for_deletion, Lisp_Object nor tty->top_frame = frame; } + sf->select_mini_window_flag = MINI_WINDOW_P (XWINDOW (sf->selected_window)); + selected_frame = frame; + + move_minibuffers_onto_frame (sf, for_deletion); + + if (f->select_mini_window_flag + && !NILP (Fminibufferp (XWINDOW (f->minibuffer_window)->contents, Qt))) + f->selected_window = f->minibuffer_window; + f->select_mini_window_flag = false; + if (! FRAME_MINIBUF_ONLY_P (XFRAME (selected_frame))) last_nonminibuf_frame = XFRAME (selected_frame); @@ -1559,7 +1570,6 @@ do_switch_frame (Lisp_Object frame, int track, int for_deletion, Lisp_Object nor #endif internal_last_event_frame = Qnil; - move_minibuffers_onto_frame (sf, for_deletion); return frame; } diff --git a/src/frame.h b/src/frame.h index 75a0b184c1..cad3df5ae1 100644 --- a/src/frame.h +++ b/src/frame.h @@ -462,6 +462,11 @@ struct frame in X builds only. */ bool_bf was_invisible : 1; + /* True when the frame isn't selected, and selecting it in the + future should select the mini-window rather than the currently + selected window in the frame, assuming there is still an active + minibuffer in that mini-window. */ + bool_bf select_mini_window_flag : 1; /* Bitfield area ends here. */ /* This frame's change stamp, set the last time window change diff --git a/src/window.c b/src/window.c index 9961c54161..f0451359c1 100644 --- a/src/window.c +++ b/src/window.c @@ -468,6 +468,7 @@ Return WINDOW. */) else { fset_selected_window (XFRAME (frame), window); + /* Don't clear FRAME's select_mini_window_flag here. */ return window; } } @@ -517,6 +518,9 @@ select_window (Lisp_Object window, Lisp_Object norecord, /* Do not select a tooltip window (Bug#47207). */ error ("Cannot select a tooltip window"); + /* We deinitely want to select WINDOW, not the mini-window. */ + f->select_mini_window_flag = false; + /* Make the selected window's buffer current. */ Fset_buffer (w->contents); @@ -3242,6 +3246,9 @@ window-start value is reasonable when this function is called. */) if (EQ (selected_frame, w->frame)) Fselect_window (window, Qnil); else + /* Do not clear f->select_mini_window_flag here. If the + last selected window on F was an active minibuffer, we + want to return to it on a later Fselect_frame. */ fset_selected_window (f, window); } } @@ -5153,7 +5160,10 @@ Signal an error when WINDOW is the only window on its frame. */) if (EQ (FRAME_SELECTED_WINDOW (f), selected_window)) Fselect_window (new_selected_window, Qt); else - fset_selected_window (f, new_selected_window); + /* Do not clear f->select_mini_window_flag here. If the + last selected window on F was an active minibuffer, we + want to return to it on a later Fselect_frame. */ + fset_selected_window (f, new_selected_window); unblock_input (); > > martin -- Alan Mackenzie (Nuremberg, Germany).