From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Yuri Khan Newsgroups: gmane.emacs.help Subject: Re: How to determine (from Elisp) whether the Emacs frame has focus? Date: Sat, 14 Nov 2015 16:54:35 +0600 Message-ID: References: <87fv09o9p5.fsf@mbork.pl> <83twopdmz4.fsf@gnu.org> <876115as66.fsf@mbork.pl> <83io55dkim.fsf@gnu.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1447515869 10506 80.91.229.3 (14 Nov 2015 15:44:29 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 14 Nov 2015 15:44:29 +0000 (UTC) Cc: "help-gnu-emacs@gnu.org" To: Eli Zaretskii Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sat Nov 14 16:44:29 2015 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Zxd08-0006F0-Cn for geh-help-gnu-emacs@m.gmane.org; Sat, 14 Nov 2015 16:44:28 +0100 Original-Received: from localhost ([::1]:35378 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zxd07-0000oP-ID for geh-help-gnu-emacs@m.gmane.org; Sat, 14 Nov 2015 10:44:27 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:47695) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZxYTy-000648-1P for help-gnu-emacs@gnu.org; Sat, 14 Nov 2015 05:54:58 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZxYTx-0000g1-58 for help-gnu-emacs@gnu.org; Sat, 14 Nov 2015 05:54:57 -0500 Original-Received: from mail-lb0-x232.google.com ([2a00:1450:4010:c04::232]:36534) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZxYTv-0000f6-Jp; Sat, 14 Nov 2015 05:54:55 -0500 Original-Received: by lbblt2 with SMTP id lt2so66832067lbb.3; Sat, 14 Nov 2015 02:54:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc:content-type:content-transfer-encoding; bh=RD0VHYeR3NBgdZ4EN+VfQaoY5KkfIapfonEa/xBwoDk=; b=D/SIQLYz1xtaQOSdQ/8nYZZt/V/kyE7wRlyA96KRLe+hDMwi//msyMVAniOFbmsyji eCHjPqMpOJHPF/Tsx9k4bRdTDA4rVw+aNbPYmkOYxSDJJUP4LAJvwAp/WtznCequTXv8 2dbfMR1bEfu15kGn8qxzh+bBTo2fI4WAKH5eNDmDdpoGcODT2/VMBgv7T54pSQxhOB7S 2wIrnZMJ9cvS+JL0thT+R9Wf9Lu0LH5b2jbf7jjiXPFdl1Y8E16XaMayy9EtNbDMbsQT nqKRHFnyGqVFodZu0+QUFt0maACFZUccSuI0tgsetu8hAvp0+U+pvRlV2KupSA/R1Uc1 LQ3w== X-Received: by 10.112.54.169 with SMTP id k9mr12422740lbp.95.1447498494437; Sat, 14 Nov 2015 02:54:54 -0800 (PST) Original-Received: by 10.112.212.43 with HTTP; Sat, 14 Nov 2015 02:54:35 -0800 (PST) In-Reply-To: <83io55dkim.fsf@gnu.org> X-Google-Sender-Auth: EuHU1qfYm3eNTC9Pdmit_puqre4 X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:4010:c04::232 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:108064 Archived-At: On Sat, Nov 14, 2015 at 2:59 PM, Eli Zaretskii 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: "#". 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: "#", although this fr= ame doesn=E2=80=99t have focus. Neither does any, in fact. Now let=E2=80=99s 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 =E2=80=9Cthe=E2=80=9D selected frame, from Emacs=E2=80=99 = point of view?