emacs-elpa-diffs
[Top][All Lists]
Advanced

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

[nongnu] elpa/auto-dim-other-buffers 8d7ef78b4a 65/82: Prefer ‘after-fo


From: ELPA Syncer
Subject: [nongnu] elpa/auto-dim-other-buffers 8d7ef78b4a 65/82: Prefer ‘after-focus-change-function’
Date: Mon, 12 Dec 2022 20:58:45 -0500 (EST)

branch: elpa/auto-dim-other-buffers
commit 8d7ef78b4aab1191b22552c627455785edfb1621
Author: Michal Nazarewicz <mina86@mina86.com>
Commit: Michal Nazarewicz <mina86@mina86.com>

    Prefer ‘after-focus-change-function’
    
    Prefer hooking into ‘after-focus-change-function’ rather than
    deprecated since Emacs 27.1 ‘focus-out-hook’ and ‘focus-in-hook’
    hooks.
---
 auto-dim-other-buffers.el | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)

diff --git a/auto-dim-other-buffers.el b/auto-dim-other-buffers.el
index 27cfbaf69d..78e0cce802 100644
--- a/auto-dim-other-buffers.el
+++ b/auto-dim-other-buffers.el
@@ -133,15 +133,29 @@ Currently only mini buffer and echo areas are ignored."
       (adob--undim-buffer)
       (setq adob--last-buffer (current-buffer)))))
 
+(defun adob--focus-change-hook ()
+  "Based on focus status of selected frame dim or undim selected buffer.
+Do nothing if `auto-dim-other-buffers-dim-on-focus-out' is nil."
+  (if (with-no-warnings (frame-focus-state))
+      (adob--focus-in-hook)
+    (adob--focus-out-hook)))
+
 ;;;###autoload
 (define-minor-mode auto-dim-other-buffers-mode
   "Visually makes non-current buffers less prominent"
   :global t
   (let ((callback (if auto-dim-other-buffers-mode #'add-hook #'remove-hook)))
-    (dolist (args '((buffer-list-update-hook adob--buffer-list-update-hook)
-                    (focus-out-hook adob--focus-out-hook)
-                    (focus-in-hook adob--focus-in-hook)))
-      (apply callback args)))
+    (funcall callback 'buffer-list-update-hook #'adob--buffer-list-update-hook)
+    ;; Prefer ‘after-focus-change-function’ (which was added in Emacs 27.1) to
+    ;; ‘focus-out-hook’ and ‘focus-in-hook’.
+    (if (boundp 'after-focus-change-function)
+        (if auto-dim-other-buffers-mode
+            (add-function :after after-focus-change-function
+                          #'adob--focus-change-hook)
+          (remove-function after-focus-change-function
+                           #'adob--focus-change-hook))
+      (funcall callback 'focus-out-hook #'adob--focus-out-hook)
+      (funcall callback 'focus-in-hook #'adob--focus-in-hook)))
 
   (save-current-buffer
     (if auto-dim-other-buffers-mode



reply via email to

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