unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Andrea Greselin <greselin.andrea@gmail.com>
To: Help Gnu Emacs mailing list <help-gnu-emacs@gnu.org>
Subject: Re: Ignore spurious focus events for ‘after-focus-change-function’
Date: Sat, 16 Jan 2021 10:56:51 +0100	[thread overview]
Message-ID: <CAJ_oJbaWN5QGoRrqaU+gbqCG4aaCAOHX6F_=6=O3MsTr6VjLAQ@mail.gmail.com> (raw)
In-Reply-To: <CAJ_oJbZb3_7EoOZJJr9nPy+W913ruH+pP-APtLQwYTkvNEY3iw@mail.gmail.com>

Hi Eli, I need it for triggering auto-save on focus-out and functions
that dim some colours on focus-out and restore them on focus-in.

Auto-save works when it should, and also when it shouldn't. Changing
the colours on focus out works well but there's some flickering when
they're restored on focus in, which I think may be due to the excess
focus events triggering it repeatedly.

Also, I have an issue with the tab-bar when the Solarized theme is
enabled (the GUI keys -- new tab, close tab, the tab itself -- don't
work when I click on them) and I'm trying to debug it. It must be
something in my configuration because there are no problems with
Solarized in ‘emacs -Q’. I wanted to ignore the spurious focus events
as part of debugging this issue.

> In any case, I very much doubt that "deferring work until redisplay"
> meant that you should _trigger_ redisplay by calling sit-for.

I had tried with ‘(sit-for 0 t)’ first, wich *maybe* was bit cleverer
but yes, it was naive. Now I have something that seems to be working,
from a suggestion on Reddit [1]

  (defvar focus-out-auto-save-timer nil)

  (defun focus-test () (message "ffs: %s" (frame-focus-state)) (setq
    focus-out-auto-save-timer nil))

  (defun focus-test-wrapper () (setq focus-out-auto-save-timer (unless
    (timerp focus-out-auto-save-timer) (run-at-time "0.05 sec" nil
    #'focus-test))))

  (add-function :after after-focus-change-function
  #'focus-test-wrapper)

It's not super-robust (works with delay >= 0.05 s, doesn't work if
it's <= 0.01 s) but it's done its job for the couple of times I tested
it. In particular, it does not see focus-out events unless one
actually happens. I still hope there is a cleaner way, I don't like
this one very much.

1
https://www.reddit.com/r/emacs/comments/kxsgtn/ignore_spurious_focus_events_for/


  parent reply	other threads:[~2021-01-16  9:56 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-15 20:26 Ignore spurious focus events for ‘after-focus-change-function’ Andrea Greselin
2021-01-16  7:02 ` Eli Zaretskii
2021-01-16  9:56 ` Andrea Greselin [this message]
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

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAJ_oJbaWN5QGoRrqaU+gbqCG4aaCAOHX6F_=6=O3MsTr6VjLAQ@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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).