From: Andrea Greselin <greselin.andrea@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Ignore spurious focus events for ‘after-focus-change-function’
Date: Fri, 15 Jan 2021 21:26:32 +0100 [thread overview]
Message-ID: <CAJ_oJbZb3_7EoOZJJr9nPy+W913ruH+pP-APtLQwYTkvNEY3iw@mail.gmail.com> (raw)
Hello everyone, I'm on Emacs 27.1, Fedora 33, GNOME 3.38.2.
In the latest ‘NEWS’ it is reported that
> The hooks ‘focus-in-hook’ and ‘focus-out-hook’ are now obsolete.
> Instead, attach to ‘after-focus-change-function’ using
> ‘add-function’ and inspect the focus state of each frame using
> ‘frame-focus-state’.
The documentation for ‘after-focus-change-function’ says
> Depending on window system, focus events may also be delivered
> repeatedly and with different focus states before settling to the
> expected values. Code relying on focus notifications should
> "debounce" any user-visible updates arising from focus changes,
> perhaps by deferring work until redisplay.
Indeed, after evaluating this code,
(defun focus-test ()
(message "ffs: %s" (frame-focus-state)))
(add-function :after after-focus-change-function #'focus-test)
every time I switch buffer by selecting one with the mouse my message
buffer shows
ffs: nil
ffs: t
ffs: nil
ffs: t
That is, Emacs sees two back and forth focus changes where I did none,
and most importantly it has hallucinations of focus-out events which
defeat the usefulness of the
‘after-focus-change-function’+‘frame-focus-state’ method for
triggering functions based on focus events.
My question is, how do I "'debounce' any user-visible updates arising
from focus changes"? I made a couple of attempts, with
(defun focus-test ()
(sit-for 0)
(message "ffs: %s" (frame-focus-state)))
and
(defun payload (_window)
(message "ffs: %s" (frame-focus-state))
(remove-hook 'pre-redisplay-functions #'payload))
(defun focus-test ()
(add-hook 'pre-redisplay-functions #'payload))
(add-function :after after-focus-change-function #'focus-test)
but it didn't work.
Andrea
next reply other threads:[~2021-01-15 20:26 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-15 20:26 Andrea Greselin [this message]
2021-01-16 7:02 ` Ignore spurious focus events for ‘after-focus-change-function’ Eli Zaretskii
2021-01-16 9:56 ` Andrea Greselin
2021-01-18 19:09 ` Andrea Greselin
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAJ_oJbZb3_7EoOZJJr9nPy+W913ruH+pP-APtLQwYTkvNEY3iw@mail.gmail.com \
--to=greselin.andrea@gmail.com \
--cc=help-gnu-emacs@gnu.org \
/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 external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.