help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to determine (from Elisp) whether the Emacs frame has focus?


From: Yuri Khan
Subject: Re: How to determine (from Elisp) whether the Emacs frame has focus?
Date: Sat, 14 Nov 2015 16:54:35 +0600

On Sat, Nov 14, 2015 at 2:59 PM, Eli Zaretskii <eliz@gnu.org> wrote:
>>
>> "Focus" in the window manager sense, not in Emacs sense.  I.e., I want
>> to determine whether it is Emacs which receives keystrokes, or some
>> other X application.
>>
>> Hope that clarifies the question.
>
> Not really, sorry.  The function selected-frame returns the frame that
> receives keystrokes, at least as far as I understand what you are
> saying.  The ELisp manual explicitly says:
>
>    -- Function: selected-frame
>        This function returns the selected frame.

OK, simple demonstration.

I have a couple Emacs frames on my desktop, along with a Firefox and
an Xterm, all under the i3 window manager (but the concepts should
apply to any wm).

In one of the Emacs frames, I bring up *scratch* and type:

(progn (sit-for 3) (message "%s" (selected-frame)))

I press C-x C-e on that and wait for three seconds. It says: "#<frame
*scratch* – Emacs 0x1140678>".

Now I press C-x C-e again, and before three seconds elapse, I switch
the wm focus to Firefox. However, after three seconds, the minibuffer
says again: "#<frame *scratch* – Emacs #1140678>", although this frame
doesn’t have focus. Neither does any, in fact.


Now let’s imagine a situation where there is a single Emacs server,
and a couple of emacsclients connected to it, both displaying their
respective frames *on different X servers*. I believe in that setup
both frames could simultaneously have focus in their respective wms.
Which of them is “the” selected frame, from Emacs’ point of view?



reply via email to

[Prev in Thread] Current Thread [Next in Thread]