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

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

[elpa] externals/ement 3dc6849c1c 1/2: Add: (ement-notify-mark-frame-urg


From: ELPA Syncer
Subject: [elpa] externals/ement 3dc6849c1c 1/2: Add: (ement-notify-mark-frame-urgent-predicates)
Date: Mon, 26 Sep 2022 13:57:40 -0400 (EDT)

branch: externals/ement
commit 3dc6849c1c32ebfe31dee3b77ab94ffcce03af34
Author: Adam Porter <adam@alphapapa.net>
Commit: Adam Porter <adam@alphapapa.net>

    Add: (ement-notify-mark-frame-urgent-predicates)
---
 README.org      |  1 +
 ement-notify.el | 43 ++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 43 insertions(+), 1 deletion(-)

diff --git a/README.org b/README.org
index 83ef9c25f0..6d0ca3afdb 100644
--- a/README.org
+++ b/README.org
@@ -294,6 +294,7 @@ Note that, while ~matrix-client~ remains usable, and 
probably will for some time
 + Command ~ement-directory-next~ fetches the next batch of rooms in a 
directory.
 + Command ~ement-leave-room~ accepts a ~FORCE-P~ argument (interactively, with 
prefix) to leave a room without prompting.
 + Command ~ement-forget-room~ accepts a ~FORCE-P~ argument (interactively, 
with prefix) to also leave the room, and to forget it without prompting.
++ Option ~ement-notify-mark-frame-urgent-predicates~ marks the frame as urgent 
when (by default) a message mentions the local user or "@room" and the 
message's room has an open buffer.
 
 *Changes*
 + Minor improvements to date/time headers.
diff --git a/ement-notify.el b/ement-notify.el
index 2b0016021d..8faf18b9b2 100644
--- a/ement-notify.el
+++ b/ement-notify.el
@@ -83,6 +83,17 @@ If one of these returns non-nil for an event, the event is 
logged."
              ement-notify--room-buffer-live-p
              ement-notify--room-unread-p))
 
+(defcustom ement-notify-mark-frame-urgent-predicates
+  '(ement-notify--event-mentions-session-user-p
+    ement-notify--event-mentions-room-p)
+  "Predicates to determine whether to mark a frame as urgent.
+If one of these returns non-nil for an event, the frame that most
+recently showed the event's room's buffer is marked
+urgent.  (Only works on X, not other GUI platforms.)"
+  :type 'hook
+  :options '(ement-notify--event-mentions-session-user-p
+             ement-notify--event-mentions-room-p))
+
 (defcustom ement-notify-mention-predicates
   '(ement-notify--event-mentions-session-user-p
     ement-notify--event-mentions-room-p)
@@ -178,7 +189,37 @@ Does not do anything if session hasn't finished initial 
sync."
     (when (run-hook-with-args-until-success 'ement-notify-log-predicates event 
room session)
       (ement-notify--log-to-buffer event room session))
     (when (run-hook-with-args-until-success 'ement-notify-mention-predicates 
event room session)
-      (ement-notify--log-to-buffer event room session :buffer-name "*Ement 
Mentions*"))))
+      (ement-notify--log-to-buffer event room session :buffer-name "*Ement 
Mentions*"))
+    (when (run-hook-with-args-until-success 
'ement-notify-mark-frame-urgent-predicates event room session)
+      (ement-notify--mark-frame-urgent event room session))))
+
+(defun ement-notify--mark-frame-urgent (_event room _session)
+  "Mark frame showing ROOM's buffer as urgent.
+If ROOM has no existing buffer, do nothing."
+  (cl-labels ((mark-frame-urgent
+               (frame) (let* ((prop "WM_HINTS")
+                              (hints (cl-coerce
+                                      (x-window-property prop frame prop nil 
nil t)
+                                      'list)))
+                         (setf (car hints) (logior (car hints) 256))
+                         (x-change-window-property prop hints nil prop 32 t))))
+    (when-let* ((buffer (alist-get 'buffer (ement-room-local room)))
+                (frames (cl-loop for frame in (frame-list)
+                                 when (eq 'x (framep frame))
+                                 collect frame))
+                (frame (pcase (length frames)
+                         (1 (car frames))
+                         (_
+                          ;; Use the frame that most recently showed ROOM's 
buffer.
+                          (car (sort frames
+                                     (lambda (frame-a frame-b)
+                                       (let ((a-pos (cl-position buffer 
(buffer-list frame-a)))
+                                             (b-pos (cl-position buffer 
(buffer-list frame-b))))
+                                         (cond ((and a-pos b-pos)
+                                                (< a-pos b-pos))
+                                               (a-pos)
+                                               (b-pos))))))))))
+      (mark-frame-urgent frame))))
 
 (defun ement-notify--notifications-notify (event room _session)
   "Call `notifications-notify' for EVENT in ROOM on SESSION."



reply via email to

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