unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: martin rudalics <rudalics@gmx.at>
To: Drew Adams <drew.adams@oracle.com>
Cc: 11566@debbugs.gnu.org
Subject: bug#11566: 24.0.97; `read-from-minibuffer': focus to standalone minibuffer frame?
Date: Sun, 27 May 2012 15:22:21 +0200	[thread overview]
Message-ID: <4FC22A8D.6040801@gmx.at> (raw)
In-Reply-To: <6A40227DCFBF427491B710A473E45744@us.oracle.com>

 > On MS Windows at least, when a new frame is created it grabs the input
 > focus.  The problem where the minibuffer frame does not get the focus it
 > needs seems to arise in a situation where a new frame is popped up and
 > then `read-from-minibuffer' is called immediately afterward.  Maybe
 > there is some kind of contention or delay/race problem here (?) - I have
 > no idea.

You should be able to check this by inserting a (sit-for 1) somewhere in
between popping up the frame and calling `read-from-minibuffer'.

 > For example, `dired-mark-read-string' calls `dired-mark-pop-up' to read
 > a string using `read-from-minibuffer' (`r-f-m' is the FUNCTION arg
 > passed to `d-m-p-u' in this case).
 >
 > Inside a `save-window-excursion', `dired-mark-pop-up' then calls
 > `dired-pop-to-buffer', which pops up a new buffer, which (let's say,
 > because of `special-display-regexp' or whatever) is shown in a new
 > frame.  MS Windows gives this frame the input focus.
 >
 > Then, still inside the `save-window-excursion', `dired-mark-pop-up'
 > immediately calls the FUNCTION arg, which in this case is
 > `read-from-minibuffer'.  (It does this using (apply FUNCTION args), but
 > that should not make any difference.)
 >
 > [I don't think it matters for correctness whether the (apply FUNCTION
 > args) is inside the `save-window-excursion'.  I've tried moving it
 > outside, but that did not change anything.  I would think that it should
 > be outside logically (why perform the action from that buffer?), but I'm
 > not knowledgeable about all use cases of `dired-mark-pop-up'.]

IIRC _you_ don't need the `save-window-excursion'.  So replace it with a
`progn' and I'm sure you won't notice any difference.

 > OK, so what happens is this: When `read-from-minibuffer' does its thing,
 > the standalone minibuffer does not receive the user input.  Instead, the
 > input goes to the popped-up frame (which has a list of *Marked Files*).
 >
 > That seems to be an exception to the general rule that
 > `read-from-minibuffer' correctly moves the focus to the minibuffer - and
 > to its frame.

IIUC `read-from-minibuffer' uses `redirect-frame-focus' to send the
keystrokes to the minibuffer window.  If that function works for you in
general, we likely have a race condition in this special case.

 > I don't know why there is a difference in this case, but
 > that seems to be what happens.  The problem is not specific to this
 > example - it can occur at other times.  But I think that this is a good
 > case to follow what's happening.
 >
 > I've tried various workarounds, with more or less success.  But I'm
 > thinking now that the problem is not in any such functions that pop up a
 > frame etc. but rather with `read-from-minibuffer' itself.  Shouldn't it
 > have the responsibility here to give the minibuffer frame the focus?

Yes.  But the window manager must not intercept it.

 > Here is a workaround I've come up with when trying to "fix" `r-f-m'
 > itself:
 >
 > (defadvice read-from-minibuffer (around focus-standalone-minibuf activate)
 >   "..."
 >   (let ((selframe  (selected-frame))
 >         result)
 >     (unwind-protect
 >          (progn (when (and (boundp '1on1-minibuffer-frame)
 >                            (frame-live-p 1on1-minibuffer-frame))
 >                   (select-frame-set-input-focus 1on1-minibuffer-frame))
 >                 (setq result  ad-do-it))
 >       (ignore-errors (select-frame-set-input-focus selframe))
 >       result)))
 >
 > (In my case I know that the standalone minibuffer, if it exists, is the
 > value of `1on1-minibuffer-frame'.  Not sure how the use of a standalone
 > minibuffer would be detected in general - presumably by checking for a
 > frame that has a `minibuffer' parameter with value `only'...)
 >
 > But that defadvice does not always make `r-f-m' DTRT, in any case.  For
 > example, if the originally selected frame is deleted during `ad-do-it',
 > then it punts and leaves the input focus in the minibuffer frame.  What
 > I would probably expect (want) in that case is for the previously
 > selected frame to get the focus.

I'm afraid that in this special case the current code will fail as well.

 > For example, if I tweak `dired-mark-pop-up' so that it deletes the
 > popped up frame at the end, then - since that frame was selected (by the
 > window manager) when `read-from-minibuffer' was called - the minibuffer
 > frame ends up with the focus.
 >
 > (And I do tweak `d-m-p-u' that way, because of another problem with such
 > a popped up frame - see bug #7533.)
 >
 > Any help is appreciated.  Hope I've made the problem clear enough,
 > though you would probably have to be on Windows to see it manifested.
 > I really hope that someone with better understanding than I can help.

Try the sit-for approach.  Try to make a standalone example like

(let ((old-frame ... some existing frame))
   (make-frame)
   (redirect-frame-focus old-frame))

and see whether it fails giving focus to `old-frame'.

martin





  reply	other threads:[~2012-05-27 13:22 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-27  0:07 bug#11566: 24.0.97; `read-from-minibuffer': focus to standalone minibuffer frame? Drew Adams
2012-05-27 13:22 ` martin rudalics [this message]
2012-05-27 15:01   ` Drew Adams
2012-05-29  9:43     ` martin rudalics
2012-05-29 14:12       ` Drew Adams
2012-05-29 15:44         ` Eli Zaretskii
2012-05-29 16:10           ` Drew Adams
2012-05-29 16:44             ` Eli Zaretskii
2012-05-29 19:15               ` Drew Adams
2012-05-29 19:47                 ` Eli Zaretskii
2012-05-29 20:28                   ` Drew Adams
2012-05-29 15:40       ` Eli Zaretskii
2012-05-29 16:10         ` Drew Adams
2012-05-29 16:46           ` Eli Zaretskii
2012-05-29 19:15             ` Drew Adams
2012-05-29 20:20               ` Eli Zaretskii
2012-05-29 21:31                 ` Drew Adams
2012-05-30 18:43                   ` Eli Zaretskii
2012-05-30 20:10                     ` Drew Adams
2012-05-28 18:02 ` Drew Adams
2012-10-03  9:13 ` martin rudalics

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=4FC22A8D.6040801@gmx.at \
    --to=rudalics@gmx.at \
    --cc=11566@debbugs.gnu.org \
    --cc=drew.adams@oracle.com \
    /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).