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: Emanuel Berg
Subject: Re: How to determine (from Elisp) whether the Emacs frame has focus?
Date: Sat, 14 Nov 2015 04:48:09 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux)

Marcin Borkowski <mbork@mbork.pl> 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




reply via email to

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