From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Emanuel Berg Newsgroups: gmane.emacs.help Subject: Re: How to determine (from Elisp) whether the Emacs frame has focus? Date: Sat, 14 Nov 2015 04:48:09 +0100 Message-ID: <87mvuh44xy.fsf@debian.uxu> References: <87fv09o9p5.fsf@mbork.pl> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1447472351 14660 80.91.229.3 (14 Nov 2015 03:39:11 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 14 Nov 2015 03:39:11 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sat Nov 14 04:39:00 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 1ZxRg2-0005e5-Hq for geh-help-gnu-emacs@m.gmane.org; Sat, 14 Nov 2015 04:38:58 +0100 Original-Received: from localhost ([::1]:57579 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZxRg2-00049V-4H for geh-help-gnu-emacs@m.gmane.org; Fri, 13 Nov 2015 22:38:58 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:35966) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZxRfq-000489-EU for help-gnu-emacs@gnu.org; Fri, 13 Nov 2015 22:38:47 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZxRfn-00023u-6H for help-gnu-emacs@gnu.org; Fri, 13 Nov 2015 22:38:46 -0500 Original-Received: from plane.gmane.org ([80.91.229.3]:47508) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZxRfm-00022U-Vg for help-gnu-emacs@gnu.org; Fri, 13 Nov 2015 22:38:43 -0500 Original-Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1ZxRfe-00059t-Km for help-gnu-emacs@gnu.org; Sat, 14 Nov 2015 04:38:34 +0100 Original-Received: from nl106-137-244.student.uu.se ([130.243.137.244]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sat, 14 Nov 2015 04:38:34 +0100 Original-Received: from embe8573 by nl106-137-244.student.uu.se with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sat, 14 Nov 2015 04:38:34 +0100 X-Injected-Via-Gmane: http://gmane.org/ Mail-Followup-To: help-gnu-emacs@gnu.org Original-Lines: 25 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: nl106-137-244.student.uu.se Mail-Copies-To: never User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux) Cancel-Lock: sha1:2krSiPX5sCc1BXa/knbvoIIVnJU= X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 80.91.229.3 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:108050 Archived-At: Marcin Borkowski writes: > I'd like to know whether the selected Emacs frame > has focus. Currently, I'm using an xdotool/xprop > combo (I'm on GNU/Linux), but I'd like to know > whether there is a better way. I know about > focus-in-hook and focus-out-hook, and I could make > them set/unset some global variable, but this > looks hackish. Try this: (defun emacs-window-has-focus () (interactive) ; interactive to test, with the line below... (sleep-for 3) ; ...so you have time to change the window (let ((focused-window-pid (string-to-number (shell-command-to-string "wmctrl -l -p | grep `xprop -root _NET_ACTIVE_WINDOW | cut -d x -f 2` | cut -d ' ' -f 4") ))) (message (if (= (emacs-pid) focused-window-pid) "has" "not so")) )) -- underground experts united http://user.it.uu.se/~embe8573