diff --git a/oni-circe.el b/oni-circe.el index d3cfbf5..0a674de 100644 --- a/oni-circe.el +++ b/oni-circe.el @@ -95,51 +95,52 @@ which may be encrypted." (enable-circe-color-nicks) (enable-circe-serenity) -;; (require 'mowedline) +;;; Polybar +;; This was originally written by retroj in his own configuration and shared +;; with me from when I was using mowedline. I've adapted the code to work for +;; polybar instead and renamed all of the functions. -;; (defun mowedline-colorize-mode-line-spec (s) -;; (cond -;; ((stringp s) (string-trim s)) -;; ((eq ':propertize (car s)) -;; (let ((s (cadr s)) -;; (face (plist-get (cddr s) 'face))) -;; (if face -;; `(color ,(face-foreground face) -;; ,(substring-no-properties s)) -;; s))) -;; (t ""))) +(defvar oni-circe-tracking-buffers nil) +(defvar oni-circe-tracking-timer nil) -;; (setq mowedline-update-function 'mowedline-update/dbus) +(defun oni-circe-colorize (s) + "Turn any color description of S into one that Polybar understands." + (cond + ((stringp s) (string-trim s)) + ((eq ':propertize (car s)) + (let ((s (cadr s)) + (face (plist-get (cddr s) 'face))) + (if face + (format "%%{F%s}%s%%{F-}" + (face-foreground face) + (substring-no-properties s)) + s))) + (t ""))) -;; (defvar jjf-tracking-buffers '()) -;; (defvar jjf-external-tracking-timer nil) -;; (defun jjf-external-tracking () -;; (setq jjf-external-tracking-timer nil) -;; (mowedline-update -;; 'irc -;; (if (stringp jjf-tracking-buffers) -;; (mowedline-colorize jjf-tracking-buffers t) -;; (format "%S" (mapcar #'mowedline-colorize-mode-line-spec -;; jjf-tracking-buffers))))) +(defun oni-circe-update-polybar () + "Send a command to Polybar to update my Circe widget." + (setq oni-circe-tracking-timer nil) + (shell-command (format "polybar-msg action circe send %s" + (shell-quote-argument + (if (stringp oni-circe-tracking-buffers) + (oni-circe-colorize oni-circe-tracking-buffers) + (mapconcat #'oni-circe-colorize oni-circe-tracking-buffers)))))) -;; (defun oni:clear-irc-mowedline-widget () -;; (mowedline-clear 'irc)) +(defun oni-circe-polybar-tracking (orig-fun &rest args) + "Update my external status bar when tracking computes a new status line. -;; (defun jjf-external-tracking-advice (orig-fun &rest args) -;; "Update my external status bar when tracking computes a new -;; status line, and suppress tracking in the mode-line. Since -;; tracking-status may be called many times in quick succession, for -;; example on a make-frame-visible event, we use a short timer to -;; only call the updater once within a minimum duration." -;; (setq jjf-tracking-buffers (apply orig-fun args)) -;; (when jjf-external-tracking-timer -;; (cancel-timer jjf-external-tracking-timer)) -;; (setq jjf-external-tracking-timer -;; (run-at-time 0.2 nil 'jjf-external-tracking)) -;; nil) +Also suppress tracking in the mode-line. Since tracking-status +may be called many times in quick succession, for example on a +make-frame-visible event, we use a short timer to only call the +updater once within a minimum duration." + (setq oni-circe-tracking-buffers (apply orig-fun args)) + (when oni-circe-tracking-timer + (cancel-timer oni-circe-tracking-timer)) + (setq oni-circe-tracking-timer + (run-at-time 0.2 nil #'oni-circe-update-polybar)) + nil) -;;(advice-add 'tracking-status :around #'jjf-external-tracking-advice) -;;(add-hook 'kill-emacs-hook 'oni:clear-irc-mowedline-widget) +(advice-add 'tracking-status :around #'oni-circe-polybar-tracking) (add-hook 'circe-channel-mode-hook 'olivetti-mode)