[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Ignore spurious focus events for ‘after-focus-change-function’
From: |
Andrea Greselin |
Subject: |
Ignore spurious focus events for ‘after-focus-change-function’ |
Date: |
Fri, 15 Jan 2021 21:26:32 +0100 |
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
- Ignore spurious focus events for ‘after-focus-change-function’,
Andrea Greselin <=