unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: miha--- via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: Dmitry Gutov <dgutov@yandex.ru>, 55983@debbugs.gnu.org
Subject: bug#55983: 29.0.50; If xref-goto-xref pops up a frame, it doesn't set its input focus
Date: Sun, 19 Jun 2022 15:37:45 +0200	[thread overview]
Message-ID: <8735g0u63a.fsf@miha-pc> (raw)
In-Reply-To: <fcc3e10f-2729-3294-aa57-5a99b3db0284@yandex.ru>


[-- Attachment #1.1: Type: text/plain, Size: 1714 bytes --]

Dmitry Gutov <dgutov@yandex.ru> writes:

> Hi!
>
> Thanks for the report.
>
> On 14.06.2022 23:17, miha--- via Bug reports for GNU Emacs, the Swiss 
> army knife of text editors wrote:
>> To reproduce, customize pop-up-frames to non-nil and set up your window
>> manager such that it doesn't automatically set input focus on newly
>> created frames.
>
> TBH I'm not sure how to setup GNOME Shell to do this.
>
>> Now in an xref-mode buffer, press RET on a search result
>> (xref-goto-xref) and notice that the newly created frame doesn't receive
>> input focus. That is because xref-goto-xref uses `display-buffer',
>> followed by a `select-window'.
>> 
>> To contrast this behaviour with grep-mode, pressing RET in a grep-mode
>> buffer (compile-goto-error) does set input focus to the newly created
>> frame. That is because compile-goto-error uses `pop-to-buffer`, which
>> also calls `select-frame-set-input-focus'.
>
> Window management in Emacs is a tricky business, and the current 
> implementation is a result of https://debbugs.gnu.org/28814 which 
> implemented a particular kind of behavior and 
> https://debbugs.gnu.org/33870 which did try to make it more customizable 
> through display-buffer-alist. See both discussions for more detail.
>
> I don't have the time at the moment to try to rework it myself.
>
> Patches welcome, though. But please mind the original implementation
> intent.

Please see the attached patch. The only thing it adds is setting frame
input focus if necessary before calling `select-window'. Other behaviour
should remain the same as before. (The code and the comment is lifted
from the function `pop-to-buffer'.)

Best regards.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.2: 0001-xref-goto-xref-Set-input-focus-in-addition-to-select.patch --]
[-- Type: text/x-patch, Size: 1578 bytes --]

From 6fbdecf5e6a1726498287679bc276dfc0af0633f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Miha=20Rihtar=C5=A1i=C4=8D?= <miha@kamnitnik.top>
Date: Sun, 19 Jun 2022 15:29:59 +0200
Subject: [PATCH] xref-goto-xref: Set input focus in addition to selecting
 window

* lisp/progmodes/xref.el (xref--show-location): Set input focus in
addition to selecting displayed window (Bug#55983).
---
 lisp/progmodes/xref.el | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/lisp/progmodes/xref.el b/lisp/progmodes/xref.el
index 683589d71c..0213ab3cc5 100644
--- a/lisp/progmodes/xref.el
+++ b/lisp/progmodes/xref.el
@@ -645,9 +645,15 @@ xref--show-location
              (xref-buffer (current-buffer)))
         (cond (select
                (if (eq select 'quit) (quit-window nil nil))
-               (select-window
-                (with-current-buffer xref-buffer
-                  (xref--show-pos-in-buf marker buf))))
+               (let* ((old-frame (selected-frame))
+                      (window (with-current-buffer xref-buffer
+                                (xref--show-pos-in-buf marker buf)))
+                      (frame (window-frame window)))
+                 ;; If we chose another frame, make sure it gets input
+                 ;; focus.
+                 (unless (eq frame old-frame)
+                   (select-frame-set-input-focus frame))
+                 (select-window window)))
               (t
                (save-selected-window
                  (xref--with-dedicated-window
-- 
2.36.0


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 861 bytes --]

  reply	other threads:[~2022-06-19 13:37 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-14 20:17 bug#55983: 29.0.50; If xref-goto-xref pops up a frame, it doesn't set its input focus miha--- via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-06-19  0:01 ` Dmitry Gutov
2022-06-19 13:37   ` miha--- via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2022-06-20  0:48     ` Dmitry Gutov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8735g0u63a.fsf@miha-pc \
    --to=bug-gnu-emacs@gnu.org \
    --cc=55983@debbugs.gnu.org \
    --cc=dgutov@yandex.ru \
    --cc=miha@kamnitnik.top \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).