29 июн. 2009 г.

StumpWM + Jabber.el

Захотел получать оповещения о приходе в Jabber.el сообщений.Для этого сначала добавил в Jabber.el возможность отправки сообщений в StumpWM.
  1. Создал в директории с Jabber.el файл jabber-stumpwm.el следующего содержания:
    (eval-when-compile (require 'jabber-alert))

    (defun jabber-stumpwm-message (msg)
    "Show MSG in StumpWM"
    ;; Possible errors include not finding the stumpish (STUMPwm Interactive SHell).
    (condition-case e
    (let ((process-connection-type))
    (call-process "stumpish" nil 0 nil "notifications-add" msg))
    (error nil)))

    (define-jabber-alert stumpwm "Show a message through the StumpWM window manager"
    'jabber-stumpwm-message)
    Данный файл - копия jabber-ratpoison.el с небольшими изменениями для StumpWM. Для отправки оповещения используется STUMPwm Interactive SHell, которой в качестве аргументов передаем имя фукции оповещения и сообщение.

  2. Добавил (require 'jabber-stumpwm) в секцию External notifiers в файле jabber.el.
Функции оповещения предоставляются модулем notifications. Для его подключения в файл ~/.stumpwmrc прописываем следующее:
(load-module "notifications")
(define-key *root-map* (kbd "N") '*notifications-map*)
А к строке *screen-mode-line-format* добавляем %N.
Результат:




Полученный результат меня до конца не устроил:
- оповещения приходится удалять вручную;
- оповещения захламляют и без того перегруженную mode-line.

Пришлось внести небольшие изменения в модуль notifications, чтобы добиться желаемого:
- добавлена возможность удаления оповещений по таймауту;
- оповещения выводятся как стандартные сообщения StumpWM.
*** notifications.lisp.old 2009-06-30 15:02:31.851810478 +0400
--- notifications.lisp 2009-06-30 15:34:10.667560769 +0400
***************
*** 75,90 ****
--- 75,107 ----
(defvar notifications nil
"A list of notification strings.")

+ (defvar *notification-time* 20
+ "This variable controls how many seconds the notification will be
+ stored in the list of notifications. Don't use timer for
+ notification if the value is nil.")
+
+ (defvar *message-timeout* 1
+ "This variable controls how many seconds elapse between each update
+ of the message.")
+
+ (defvar *message-timer* nil
+ "The timer that updates the message.")
+
(defcommand notifications-add (str)
((:rest "Notification: "))
"Add a notification string.
If a notification is already included, it will be moved to the front instead of
added anew."
+ (when *notification-time*
+ (run-notification-timer))
(when (not (string= (car notifications) str))
(when (member str notifications :test #'string=)
(setf notifications (delete str notifications :test #'string=)))
(push str notifications)))

+ (defun run-notification-timer ()
+ (run-with-timer *notification-time* nil #'notifications-delete-last))
+
(defcommand notifications-reset ()
()
"Clear all notifications."
***************
*** 105,110 ****
--- 122,142 ----
"Delete the first notification."
(setf notifications (nreverse (cdr (nreverse notifications)))))

+ (defcommand notifications-start-messages ()
+ ()
+ "Start showing messages with notifications."
+ (setf *message-timer*
+ (run-with-timer 0
+ *message-timeout*
+ (lambda ()
+ (when notifications
+ (message-no-timeout (format nil "~{~a~^~%~}" notifications)))))))
+
+ (defcommand notifications-stop-messages ()
+ ()
+ "Stop showing messages with notifications."
+ (cancel-timer *message-timer*))
+
(defun notifications-as-string (&rest r)
(declare (ignore r))
(if notifications
***************
*** 126,131 ****
--- 158,165 ----
(define-key m (kbd "d") "notifications-delete-first")
(define-key m (kbd "D") "notifications-delete-last")
(define-key m (kbd "s") "notifications-show")
+ (define-key m (kbd "m") "notifications-start-messages")
+ (define-key m (kbd "M") "notifications-stop-messages")
m))

;; Local Variables:

После выполнения функции notifications-start-messages при получении сообщений получаем следующее:

Комментариев нет:

Отправить комментарий