help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Ignore spurious focus events for ‘after-focus-change-function’


From: Andrea Greselin
Subject: Re: Ignore spurious focus events for ‘after-focus-change-function’
Date: Sat, 16 Jan 2021 10:56:51 +0100

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/


reply via email to

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