From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Andrea Greselin Newsgroups: gmane.emacs.help Subject: =?UTF-8?Q?Ignore_spurious_focus_events_for_=E2=80=98after=2Dfocus=2Dchan?= =?UTF-8?Q?ge=2Dfunction=E2=80=99?= Date: Fri, 15 Jan 2021 21:26:32 +0100 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="38544"; mail-complaints-to="usenet@ciao.gmane.io" To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Fri Jan 15 21:27:33 2021 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l0Vgy-0009x1-P9 for geh-help-gnu-emacs@m.gmane-mx.org; Fri, 15 Jan 2021 21:27:32 +0100 Original-Received: from localhost ([::1]:50954 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l0Vgx-00024x-Qx for geh-help-gnu-emacs@m.gmane-mx.org; Fri, 15 Jan 2021 15:27:31 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:50374) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l0Vge-00024q-Ew for help-gnu-emacs@gnu.org; Fri, 15 Jan 2021 15:27:12 -0500 Original-Received: from mail-pj1-x1030.google.com ([2607:f8b0:4864:20::1030]:51883) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1l0Vgc-0006Hu-Qv for help-gnu-emacs@gnu.org; Fri, 15 Jan 2021 15:27:12 -0500 Original-Received: by mail-pj1-x1030.google.com with SMTP id y12so5715268pji.1 for ; Fri, 15 Jan 2021 12:27:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=6G/1LlTokI7fRDcqUuvyyPtW9aOUYcEdX9NkGzc3Y+o=; b=b9VcJKmMeV97GIdBY4Y5VK8+6LnqvNIwQszxkToZh6PO0Xa/ZxBEFtze8i7AKKqUlU aBhSKxqVvZZR4cc3Ouhlj4EMdU+j2pc53psV9vZ1j5PpOllNERdWGtC0+yTHKa/dA2Bk LiumOYU+/8ATeHIyomai1UrHDYOdQeTgifribBQEmawUrrdTDikeyRHYceqYLsOVqKcT 2JRl7WsTwMndUqnwjt43Xt7DHqMKWv56Kxtu6jwTxqATnN3t+3jxlDu3F+rlKiEUC/S6 N337Bn9xdYlJ6++seqCByGnPt3oCcVu/+w6qDYIcTaNj/FsKBPzMKKgMsZ4TE9Sf/tZw rdTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=6G/1LlTokI7fRDcqUuvyyPtW9aOUYcEdX9NkGzc3Y+o=; b=ssENXcLDS8T+LMkN+9fi1rHv2YfWZ1nErDhUERKt8BYJQKaXprdUuYMCCJ55f/GhFv j/wpw0jlMokRNJRl9k7qmUjfPl4Bdzt6BXX6x8PQPrYaU99w1Q9K0/pvRQId9lqkfnNS rKHRQ9yWObRUD+J+z7v+Ot9xtfJqEx91lS6gfh1ZLWpBHahkVquDVVyWLe+t1rVr7PM5 8200SwmUh/zjeT22O9ulfRQmVIR76tafdn6OVPdswXxesdXU+QO469MGeZ44bUB4+BZB iNdW4Nr6jaKaMdK/KQmolpaZRpz0EZwE4uBWUVcszJG2o45Y60/jI6kwPRGASC89F5J4 M17g== X-Gm-Message-State: AOAM531aXKwTZWJhbHgGcslugGGnfzf2ymOTGHetjCMY0exWSvIM0+ll wRhNbXootki4v0Wm3F6UjlIHmkz60Ibfk0BaqB7EruoPzVTz0w== X-Google-Smtp-Source: ABdhPJyvEp8p0Pa85BFeMqNPsOuz3NHSYZUrXdOfx1yS7Mu2z0UWuL+G5IcnlS7hNaZWSXo3WOspF9J5EZ7CIUSRImQ= X-Received: by 2002:a17:90b:287:: with SMTP id az7mr11123151pjb.70.1610742428551; Fri, 15 Jan 2021 12:27:08 -0800 (PST) Received-SPF: pass client-ip=2607:f8b0:4864:20::1030; envelope-from=greselin.andrea@gmail.com; helo=mail-pj1-x1030.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Content-Filtered-By: Mailman/MimeDel 2.1.23 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:127265 Archived-At: Hello everyone, I'm on Emacs 27.1, Fedora 33, GNOME 3.38.2. In the latest =E2=80=98NEWS=E2=80=99 it is reported that > The hooks =E2=80=98focus-in-hook=E2=80=99 and =E2=80=98focus-out-hook=E2= =80=99 are now obsolete. > Instead, attach to =E2=80=98after-focus-change-function=E2=80=99 using > =E2=80=98add-function=E2=80=99 and inspect the focus state of each frame = using > =E2=80=98frame-focus-state=E2=80=99. The documentation for =E2=80=98after-focus-change-function=E2=80=99 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 =E2=80=98after-focus-change-function=E2=80=99+=E2=80=98frame-focus-state=E2= =80=99 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