unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: martin rudalics <rudalics@gmx.at>
To: Andrii Kolomoiets <andreyk.mad@gmail.com>, 44415@debbugs.gnu.org
Subject: bug#44415: 27.1; Child frame loses focus on app switching
Date: Tue, 3 Nov 2020 16:57:04 +0100	[thread overview]
Message-ID: <b0ef0618-ff9c-3233-a61b-ddba172b2896@gmx.at> (raw)
In-Reply-To: <m2ft5qybod.fsf@gmail.com>

 > 1. emacs -Q
 > 2. Evaluate:
 > (select-frame-set-input-focus
 >   (make-frame `((parent-frame . ,(selected-frame)))))
 > 3. Alt-TAB
 > 4. If Emacs is not the only running app Alt-TAB to return to Emacs
 >
 > Child frame became unfocused.
 >
 > In GNU Emacs 27.1 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.22, cairo version 1.17.3)
 > Windowing system distributor 'The X.Org Foundation', version 11.0.12009000
 >
 > Same issue on Windows.

IIRC the focus is never given to a child frame in such cases.  A similar
thing happens when you have a child frame focused and you iconify its
parent.  When you deiconify the parent, the child frame loses focus too.

Maybe your problem could be solved under X as follows: According to

https://tronche.com/gui/x/xlib/events/input-focus/normal-and-grabbed.html

When the focus moves from window A to window B, window C is their least
common ancestor, and the pointer is in window P, the X server does the
following:

     If window P is an inferior of window A, it generates a FocusOut
     event on each window from window P up to but not including window A,
     with the detail member of the XFocusOutEvent structure set to
     NotifyPointer.

     It generates a FocusOut event on window A, with the detail member of
     the XFocusOutEvent structure set to NotifyNonlinear.

     It generates a FocusOut event on each window between window A and
     window C, exclusive, with the detail member of each XFocusOutEvent
     structure set to NotifyNonlinearVirtual.

We would first have to check under X whether all of the above really
happen in your case.  If so, we could remember that in some variable.
Hopefully, the third above will cover the case where the pointer is not
in the child frame but the child frame has focus.

Now the next time we get a focus-in event for the parent frame we could
then try to focus the child frame ourselves.  The tricky parts of this
are when and how to flush the above variable and how to disregard it
whenever users click with the mouse into some part of the parent frame
that is not covered by the child frame thus explicitly stating their
wish to focus the parent.

On Windows the situation looks more difficult.  But if WM_KILLFOCUS at
least does name the child frame that loses focus, we could maybe try to
emulate something similar to X.

In either case I can assure you that writing the corresponding code will
be quite tricky and require some understanding of the sequence of events
that may happen when focus changes.  But if you want to give it a try, I
will certainly try to help you.

martin





      reply	other threads:[~2020-11-03 15:57 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-03 10:30 bug#44415: 27.1; Child frame loses focus on app switching Andrii Kolomoiets
2020-11-03 15:57 ` martin rudalics [this message]

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=b0ef0618-ff9c-3233-a61b-ddba172b2896@gmx.at \
    --to=rudalics@gmx.at \
    --cc=44415@debbugs.gnu.org \
    --cc=andreyk.mad@gmail.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).