From 771abb84830678455de4625ac7f082d8100f0ea0 Mon Sep 17 00:00:00 2001 From: jao Date: Tue, 2 Feb 2021 05:16:17 +0000 Subject: libs -> lib/ --- lib/eos/jao-afio.el | 212 ++++++++++++++++++++++++++++++++++++++++++ lib/eos/jao-ednc.el | 148 +++++++++++++++++++++++++++++ lib/eos/jao-embark-targets.el | 97 +++++++++++++++++++ lib/eos/jao-minibuffer.el | 138 +++++++++++++++++++++++++++ lib/eos/jao-notify.el | 33 +++++++ lib/eos/jao-osd.el | 55 +++++++++++ lib/eos/jao-sleep.el | 58 ++++++++++++ 7 files changed, 741 insertions(+) create mode 100644 lib/eos/jao-afio.el create mode 100644 lib/eos/jao-ednc.el create mode 100644 lib/eos/jao-embark-targets.el create mode 100644 lib/eos/jao-minibuffer.el create mode 100644 lib/eos/jao-notify.el create mode 100644 lib/eos/jao-osd.el create mode 100644 lib/eos/jao-sleep.el (limited to 'lib/eos') diff --git a/lib/eos/jao-afio.el b/lib/eos/jao-afio.el new file mode 100644 index 0000000..10ca474 --- /dev/null +++ b/lib/eos/jao-afio.el @@ -0,0 +1,212 @@ +;;; jao-afio.el --- workspaces in just one frame -*- lexical-binding: t; -*- + +;; Copyright (C) 2020, 2021 jao + +;; Author: jao +;; Keywords: frames + +;; This program is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see . + +;;; Code: + +(defvar jao-afio--configs '(?c ?w ?g ?p ?s)) +(defvar jao-afio--current-config (car jao-afio--configs)) +(defvar jao-afio--locker nil) +(defvar jao-afio-fallback-fun nil) + +(defun jao-afio--check-frame-p () + (assoc 'afio (frame-parameters))) + +(defun jao-afio--init (&optional f) + (interactive) + (when (and (frame-live-p jao-afio--locker) + (not (eql f jao-afio--locker))) + (if jao-afio-fallback-fun + (funcall jao-afio-fallback-fun) + (error "Another frame is using afio"))) + (setq jao-afio--locker f) + (modify-frame-parameters f '((afio . t))) + (setq jao-afio--current-config ?c) + (mapc (lambda (r) (set-register r nil)) jao-afio--configs) + (window-configuration-to-register ?c)) + +(defun jao-afio--steal () + (interactive) + (setq jao-afio--locker nil) + (jao-afio--init (window-frame (get-buffer-window (current-buffer))))) + +(defun jao-afio--check-frame () + (unless (jao-afio--check-frame-p) + (or (when jao-afio-fallback-fun + (funcall jao-afio-fallback-fun) + t) + (when (y-or-n-p "Another frame is using afio. Steal? ") + (jao-afio--steal) + t) + (error "Aborted")))) + +(defun jao-afio--next-frame () + (interactive) + (jao-afio--check-frame) + (let* ((cur (member jao-afio--current-config jao-afio--configs)) + (next (or (cadr cur) (car jao-afio--configs)))) + (jao-afio--goto-frame next))) + +;;;###autoload +(defun jao-afio-open-doc () + (interactive) + (delete-other-windows) + (split-window-right) + (let ((docs (remove-if-not (lambda (b) + (eq (buffer-local-value 'major-mode b) + 'pdf-view-mode)) + (buffer-list)))) + (if (car docs) + (progn (switch-to-buffer (car docs)) + (switch-to-buffer-other-window (or (cadr docs) (car docs)))) + (when (and (jao-doc-view-session) + (y-or-n-p "Load saved session? ")) + (dolist (doc (jao-doc-view-session)) + (when (and (file-exists-p doc) (y-or-n-p (format "Open %s? " doc))) + (find-file doc))))))) + +;;;###autoload +(defun jao-afio-open-w3m () + (interactive) + (if (< (frame-width) 180) + (w3m) + (delete-other-windows) + (split-window-right) + (w3m) + (other-window 1) + (switch-to-buffer "*w3m*") + (ignore-errors (w3m-previous-buffer 2)))) + +;;;###autoload +(defun jao-afio-open-gnus () + (interactive) + (delete-other-windows) + (org-agenda-list) + (calendar) + (find-file (expand-file-name "inbox.org" org-directory)) + (gnus) + (jao-gnus--set-summary-line)) + +;;;###autoload +(defun jao-afio-open-mail (mail-func) + (interactive) + (delete-other-windows) + (funcall mail-func) + (jao-bisect) + (other-window 1) + (find-file (expand-file-name "inbox.org" org-directory)) + (split-window-below (/ (window-height) 3)) + (other-window 1) + (org-agenda-list) + (split-window-below -9) + (other-window 1) + (switch-to-buffer "*Calendar*") + (other-window 1)) + +(defvar jao-afio-switch-hook nil) + +(defun jao-afio--goto-frame (next &optional reset) + (let ((next-cfg (when (not reset) (get-register next)))) + (window-configuration-to-register jao-afio--current-config) + (setq jao-afio--current-config next) + (if next-cfg + (jump-to-register next) + (delete-other-windows) + (cl-case next + (?w (jao-afio-open-w3m)) + (?g (jao-afio-open-gnus)) + (?p (jao-afio-open-doc)) + (?s (delete-other-windows)))) + (run-hooks 'jao-afio-switch-hook))) + +(defun jao-afio--goto-main (&optional reset) + (interactive "P") + (jao-afio--check-frame) + (jao-afio--goto-frame ?c reset)) + +(defun jao-afio--goto-scratch (&optional reset) + (interactive "P") + (jao-afio--check-frame) + (jao-afio--goto-frame ?s reset)) + +(defun jao-afio--goto-gnus (&optional reset) + (interactive "P") + (jao-afio--check-frame) + (jao-afio--goto-frame ?g reset)) + +(defun jao-afio--goto-docs (&optional reset) + (interactive "P") + (jao-afio--check-frame) + (jao-afio--goto-frame ?p reset)) + +(defun jao-afio--goto-w3m (&optional reset) + (interactive "P") + (if (jao-afio--check-frame-p) + (jao-afio--goto-frame ?w reset) + (when (w3m-alive-p) + (pop-to-buffer (w3m-alive-p))))) + +(defun jao-afio--try-init (&optional f) + (ignore-errors (jao-afio--init f)) + t) + +(defun jao-afio--goto-w3m-buffer (buf &rest _) + (jao-afio--goto-w3m) + (jao-first-window) + (switch-to-buffer buf nil t)) + +(defun jao-afio--goto-pdf-buffer (buf &rest _) + (if (jao-afio--check-frame-p) + (progn (jao-afio--goto-docs) + (jao-first-window) + (switch-to-buffer buf nil t)) + (pop-to-buffer buf))) + +(defun jao-afio-goto-scratch (&optional one-win) + (jao-afio--goto-scratch) + (when one-win (delete-other-windows))) + +(defun jao-afio-current-frame () + (cl-case jao-afio--current-config + (?c "Main") + (?s "Scratch") + (?g "Gnus") + (?p "Docs") + (?w "Web"))) + +(defun jao-afio-current-no () + (cl-case jao-afio--current-config + (?c "1") + (?s "0") + (?g "2") + (?p "4") + (?w "3"))) + +;;;###autoload +(defun jao-afio-setup (&optional fallback-fun init-p) + (global-set-key "\C-cf" 'jao-afio--goto-main) + (global-set-key "\C-cg" 'jao-afio--goto-gnus) + (global-set-key "\C-cw" 'jao-afio--goto-w3m) + (global-set-key "\C-cz" 'jao-afio--goto-docs) + (setq jao-afio-fallback-fun fallback-fun) + (add-hook (if init-p 'after-init-hook 'after-make-frame-functions) + 'jao-afio--try-init)) + +(provide 'jao-afio) +;;; jao-afio.el ends here diff --git a/lib/eos/jao-ednc.el b/lib/eos/jao-ednc.el new file mode 100644 index 0000000..8e55a56 --- /dev/null +++ b/lib/eos/jao-ednc.el @@ -0,0 +1,148 @@ +;;; jao-ednc.el --- Minibuffer notifications using EDNC -*- lexical-binding: t; -*- + +;; Copyright (C) 2020, 2021 jao + +;; Author: jao +;; Keywords: tools, abbrev + +;; This program is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see . + +;;; Commentary: + +;; Use the ednc package to provide a notification daemon that uses +;; the minibuffer to display them. + +;;; Code: + +(require 'ednc) +(require 'jao-minibuffer) + +(declare-function tracking-add-buffer "tracking") +(declare-function tracking-remove-buffer "tracking") + +(defvar jao-ednc--count-format " {%d} ") +(defvar jao-ednc--notifications ()) +(defvar jao-ednc--handlers ()) + +(defvar jao-ednc-use-minibuffer-notifications nil) +(defvar jao-ednc-use-tracking nil) + +(defface jao-ednc-tracking '((t :inherit warning)) + "Tracking notifications face" + :group 'jao-ednc) + +(defun jao-ednc--last-notification () (car jao-ednc--notifications)) + +(defun jao-ednc--format-last () + (when (jao-ednc--last-notification) + (let ((s (ednc-format-notification (jao-ednc--last-notification) t))) + (replace-regexp-in-string "\n" " " (substring-no-properties s))))) + +(defun jao-ednc--count () + (let ((no (length jao-ednc--notifications))) + (if (> no 0) + (propertize (format jao-ednc--count-format no) 'face 'warning) + ""))) + +(defun jao-ednc-add-handler (app handler) + (add-to-list 'jao-ednc--handlers (cons app handler))) + +(defun jao-ednc-ignore-app (app) + (jao-ednc-add-handler app (lambda (not _) (ednc-dismiss-notification not)))) + +(defun jao-ednc--pop-minibuffer () + (if jao-ednc-use-minibuffer-notifications + (jao-minibuffer-pop-notification) + (jao-minibuffer-refresh))) + +(defun jao-ednc--clean (&optional notification) + (tracking-remove-buffer (get-buffer ednc-log-name)) + (if notification + (remove notification jao-ednc--notifications) + (pop jao-ednc--notifications)) + (jao-ednc--pop-minibuffer)) + +(defun jao-ednc--show-last () + (if jao-ednc-use-minibuffer-notifications + (jao-minibuffer-push-notification '(:eval (jao-ednc--format-last))) + (message "%s" (jao-ednc--format-last)))) + +(defun jao-ednc--default-handler (notification newp) + (if (not newp) + (jao-ednc--clean notification) + (tracking-add-buffer (get-buffer ednc-log-name) '(jao-ednc-tracking)) + (push notification jao-ednc--notifications) + (jao-ednc--show-last))) + +(defun jao-ednc--handler (notification) + (alist-get (ednc-notification-app-name notification) + jao-ednc--handlers + #'jao-ednc--default-handler + nil + 'string=)) + +(defun jao-ednc--on-notify (old new) + (when old (funcall (jao-ednc--handler old) old nil)) + (when new (funcall (jao-ednc--handler new) new t))) + +;;;###autoload +(defun jao-ednc-setup (minibuffer-order) + (setq jao-notify-use-messages-p t) + (with-eval-after-load "tracking" + (when jao-ednc-use-tracking + (add-to-list 'tracking-faces-priorities 'jao-ednc-tracking) + (when (listp tracking-shorten-modes) + (add-to-list 'tracking-shorten-modes 'ednc-view-mode)))) + (when minibuffer-order + (jao-minibuffer-add-variable '(jao-ednc--count) minibuffer-order)) + (add-hook 'ednc-notification-presentation-functions #'jao-ednc--on-notify) + (ednc-mode)) + +;;;###autoload +(defun jao-ednc-pop () + (interactive) + (pop-to-buffer-same-window ednc-log-name)) + +;;;###autoload +(defun jao-ednc-show () + (interactive) + (if (not (jao-ednc--last-notification)) + (jao-ednc-pop) + (jao-ednc--show-last))) + +;;;###autoload +(defun jao-ednc-invoke-last-action () + (interactive) + (if (jao-ednc--last-notification) + (ednc-invoke-action (jao-ednc--last-notification)) + (message "No active notifications")) + (jao-ednc--clean)) + +;;;###autoload +(defun jao-ednc-dismiss () + (interactive) + (when (jao-ednc--last-notification) + (ignore-errors + (with-current-buffer ednc-log-name + (ednc-dismiss-notification (jao-ednc--last-notification))))) + (jao-ednc--clean)) + +;;;###autoload +(defun jao-ednc-dismiss-all () + (interactive) + (while (jao-ednc--last-notification) + (jao-ednc-dismiss))) + +(provide 'jao-ednc) +;;; jao-ednc.el ends here diff --git a/lib/eos/jao-embark-targets.el b/lib/eos/jao-embark-targets.el new file mode 100644 index 0000000..1887b79 --- /dev/null +++ b/lib/eos/jao-embark-targets.el @@ -0,0 +1,97 @@ +;;; jao-embark-targets.el --- embark actions -*- lexical-binding: t; -*- + +;; Copyright (C) 2021 jao + +;; Author: jao +;; Keywords: convenience + +;; This program is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see . + +;;; Commentary: + +;; Embark targets and actions + +;;; Code: + +(require 'embark) + +(declare-function w3m-anchor "w3m") +(declare-function org-link-any-re "ol") +(declare-function org-open-link-from-string "ol") +(declare-function org-in-regexp "org-macs") + +(defun jao-embark-targets--org-link () + (when (derived-mode-p 'org-mode) + (when (org-in-regexp org-link-any-re) + (let ((lnk (match-string-no-properties 2))) + (if (string-match-p "http://.+" lnk) + (cons 'url lnk) + (cons 'org-link (match-string-no-properties 0))))))) + +(embark-define-keymap jao-embark-targets-org-link-map + "Actions for org links" + ((kbd "RET") org-open-link-from-string)) + +(add-to-list 'embark-target-finders #'jao-embark-targets--org-link) +(add-to-list 'embark-keymap-alist '(org-link . jao-embark-targets-org-link-map)) + +(defvar jao-embark-targets-video-url-rx + (format "^https?://\\(?:www\\.\\)?%s/.+" + (regexp-opt '("youtu.be" + "youtube.com" + "blip.tv" + "vimeo.com" + "infoq.com") + t)) + "A regular expression matching URLs that point to video streams") + +(defun jao-embark-targets--w3m-anchor () + (when (not (region-active-p)) + (when-let ((url (or (w3m-anchor) w3m-current-url))) + (cons 'url url)))) + +(defun jao-embark-targets--refine-url (url) + (if (string-match-p jao-embark-targets-video-url-rx url) + (cons 'video-url url) + (cons 'url url))) + +(defun jao-embark-targets--play-video (player url) + (interactive "sURL: ") + (let ((cmd (format "%s %s" player (shell-quote-argument url)))) + (start-process-shell-command player nil cmd))) + +(defun jao-embark-targets-mpv (&optional url) + "Play video stream with mpv" + (interactive "sURL: ") + (jao-embark-targets--play-video "mpv" url)) + +(defun jao-embark-targets-vlc (&optional url) + "Play video stream with vlc" + (interactive "sURL: ") + (jao-embark-targets--play-video "vlc" url)) + +(embark-define-keymap jao-embark-targets-video-url-map + "Actions on URLs pointing to remote video streams." + :parent embark-url-map + ("v" jao-embark-targets-vlc) + ("m" jao-embark-targets-mpv)) + +(define-key embark-url-map (kbd "f") #'browse-url-firefox) + +(add-to-list 'embark-target-finders #'jao-embark-targets--w3m-anchor) +(add-to-list 'embark-transformer-alist '(url . jao-embark-targets--refine-url)) +(add-to-list 'embark-keymap-alist '(video-url . jao-embark-targets-video-url-map)) + +(provide 'jao-embark-targets) +;;; jao-embark-targets.el ends here diff --git a/lib/eos/jao-minibuffer.el b/lib/eos/jao-minibuffer.el new file mode 100644 index 0000000..91662bf --- /dev/null +++ b/lib/eos/jao-minibuffer.el @@ -0,0 +1,138 @@ +;;; jao-minibuffer.el --- using the minibuffer to report status -*- lexical-binding: t; -*- + +;; Copyright (C) 2020, 2021 jao + +;; Author: jao +;; Keywords: extensions + +;; This program is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see . + +;;; Commentary: + +;; Simple asynchronous display of information in the minibuffer. + +;;; Code: + +(defvar jao-minibuffer-info ()) +(defvar jao-minibuffer-notification nil) +(defvar jao-minibuffer-align-right-p t) +(defvar jao-minibuffer-right-margin (if window-system 0 1)) +(defvar jao-minibuffer-maximized-frames-p nil) +(defvar jao-minibuffer-frame-width nil) +(defvar jao-minibuffer-notification-timeout 5) +(defvar jao-minibuffer-enabled-p t) + +(defconst jao-minibuffer--name " *Minibuf-0*") + +(defun jao-minibuffer--trim (s w) + (if (<= (string-width (or s "")) w) + (format (format "%%%ds" (if jao-minibuffer-align-right-p w (- w))) s) + (substring s 0 w))) + +(defun jao-minibuffer--current () + (with-current-buffer jao-minibuffer--name + (buffer-substring (point-min) (point-max)))) + +(defun jao-minibuffer--width () + (cond ((numberp jao-minibuffer-frame-width) jao-minibuffer-frame-width) + (jao-minibuffer-maximized-frames-p (frame-width)) + (t (min (frame-width) (window-width (minibuffer-window)))))) + +(defun jao-minibuffer--format-info () + (mapconcat 'string-trim + (seq-filter (lambda (s) (not (string-blank-p s))) + (mapcar 'format-mode-line + (if jao-minibuffer-align-right-p + jao-minibuffer-info + (reverse jao-minibuffer-info)))) + " ")) + +(defun jao-minibuffer--aligned (&optional w currentp) + (let* ((msg (cond (currentp (jao-minibuffer--current)) + (jao-minibuffer-notification + (format-mode-line jao-minibuffer-notification)) + (t (jao-minibuffer--format-info)))) + (msg (if jao-minibuffer-align-right-p + (string-trim msg) + (string-trim-left msg))) + (msg (propertize msg :minibuffer-message t))) + (when (not (string-empty-p msg)) + (let* ((mw (jao-minibuffer--width)) + (w (mod (or w (string-width (or (current-message) ""))) mw)) + (w (- mw w jao-minibuffer-right-margin))) + (if (> w 0) (jao-minibuffer--trim msg w) ""))))) + +(defun jao-minibuffer--set-message (msg) + (if current-minibuffer-command + msg + (let* ((msg (string-trim (replace-regexp-in-string "\n" " " msg))) + (msg (if (string-blank-p msg) msg (concat msg " ")))) + (if jao-minibuffer-align-right-p + (concat msg (jao-minibuffer--aligned (string-width (or msg "")) t)) + (concat (jao-minibuffer--aligned (+ 3 (string-width (or msg ""))) t) + " " msg))))) + +(defun jao-minibuffer--insert (msg) + (with-current-buffer jao-minibuffer--name + (erase-buffer) + (insert msg))) + +;;;###autoload +(defun jao-minibuffer-refresh () + (interactive) + (when jao-minibuffer-enabled-p + (jao-minibuffer--insert (or (jao-minibuffer--aligned) "")))) + +;;;###autoload +(defun jao-minibuffer-add-variable (variable-name &optional order) + (add-to-ordered-list 'jao-minibuffer-info `(:eval ,variable-name) order)) + +(defvar jao-minibuffer--notification-timer nil) + +(defun jao-minibuffer--start-notification-timer (timeout) + (interactive) + (when jao-minibuffer--notification-timer + (cancel-timer jao-minibuffer--notification-timer)) + (setq jao-minibuffer--notification-timer + (run-with-idle-timer (or timeout jao-minibuffer-notification-timeout) + nil + 'jao-minibuffer-pop-notification))) + +;;;###autoload +(defun jao-minibuffer-push-notification (msg &optional timeout) + (setq jao-minibuffer-notification msg) + (jao-minibuffer--start-notification-timer timeout) + (jao-minibuffer-refresh)) + +;;;###autoload +(defun jao-minibuffer-pop-notification () + (interactive) + (setq jao-minibuffer-notification nil) + (jao-minibuffer-refresh)) + +;;;###autoload +(defun jao-minibuffer-toggle () + (interactive) + (setq jao-minibuffer-enabled-p (not jao-minibuffer-enabled-p)) + (if jao-minibuffer-enabled-p + (jao-minibuffer-refresh) + (jao-minibuffer--insert ""))) + +(setq set-message-function #'jao-minibuffer--set-message) +(setq clear-message-function #'jao-minibuffer-refresh) + +(setq resize-mini-windows nil) + +(provide 'jao-minibuffer) +;;; jao-minibuffer.el ends here diff --git a/lib/eos/jao-notify.el b/lib/eos/jao-notify.el new file mode 100644 index 0000000..dc48ca4 --- /dev/null +++ b/lib/eos/jao-notify.el @@ -0,0 +1,33 @@ +;; jao-notify.el -- Interacting with notification daemon + +;; Copyright (c) 2017, 2019, 2020 Jose Antonio Ortega Ruiz + +;; Author: Jose Antonio Ortega Ruiz +;; Start date: Sun Jan 08, 2017 20:24 + + +;;; Comentary: + +;; Simple notifications using echo or dbus notifications + +;;; Code: + +(defvar jao-notify-use-messages-p nil) +(defvar jao-notify-timeout 5000) + +(declare-function notifications-notify "notifications") + +(defun jao-notify (msg &optional title icon) + (if jao-notify-use-messages-p + (message "%s%s%s" (or title "") (if title ": " "") (or msg "")) + (let* ((args `(:timeout ,jao-notify-timeout)) + (args (append args + (if title `(:title ,title :body ,msg) `(:title ,msg)))) + (args (if (and (stringp icon) (file-exists-p icon)) + (append args `(:app-icon ,(format "%s" icon))) + args))) + (apply 'notifications-notify args)))) + + +(provide 'jao-notify) +;;; jao-notify.el ends here diff --git a/lib/eos/jao-osd.el b/lib/eos/jao-osd.el new file mode 100644 index 0000000..acdc629 --- /dev/null +++ b/lib/eos/jao-osd.el @@ -0,0 +1,55 @@ +;; candy +(defvar jao-osd-cat-color-fg "black") +(defvar jao-osd-cat-color-bg "white") +(defvar jao-osd-cat-font "Andika Basic 16") +;; (setq jao-osd-cat-font "Inconsolata 20") +(defun jao-osd-cat-font (&optional font) + (or font jao-osd-cat-font)) + +(defun jao-osd-process-args (&optional font fg bg) + `("-n" ,(jao-osd-cat-font font) + "-R" ,(or bg jao-osd-cat-color-fg) "-B" ,(or fg jao-osd-cat-color-bg) + "-b" "200" "-r" "255" + "-e" "0" "-t" "2" "-d" "10" "-p" "0" "-x" "10" "-y" "10" "-u" "5000")) + +(setq jao-osd-processes (make-hash-table)) + +(defsubst jao-osd--delete-process (name) + (remhash name jao-osd-processes)) + +(defun jao-osd-process (name &optional font color) + (let ((proc (gethash name jao-osd-processes))) + (or (and proc (eq (process-status proc) 'run) proc) + (puthash name + (apply 'start-process + `("notifications" + ,(format "*notifications/%s*" name) + "aosd_cat" + ,@(jao-osd-process-args))) + jao-osd-processes)))) + +(defun jao-osd-cat (name lines) + (let* ((proc (jao-osd-process name)) + (lines (if (listp lines) lines (list lines))) + (trail (- 5 (length lines)))) + (when proc + (dolist (line lines) + (send-string proc (format "%s\n" line)))))) + ; (when (> trail 0) (send-string proc (make-string trail ?\n)))))) + +(defun jao-osd--names () + (let (names) + (maphash (lambda (n k) (push n names)) jao-osd-processes) + (reverse names))) + +(defun jao-osd-kill (name) + (let ((proc (gethash name jao-osd-processes))) + (when (processp proc) + (kill-process proc)))) + +(defun jao-osd-kill-notifiers () + (interactive) + (maphash (lambda (n p) (ignore-errors (kill-process p))) jao-osd-processes) + (clrhash jao-osd-processes)) + +(provide 'jao-osd) diff --git a/lib/eos/jao-sleep.el b/lib/eos/jao-sleep.el new file mode 100644 index 0000000..93da0e7 --- /dev/null +++ b/lib/eos/jao-sleep.el @@ -0,0 +1,58 @@ +;;; jao-sleep.el --- Actions upon sleep/awake -*- lexical-binding: t; -*- + +;; Copyright (C) 2020 jao + +;; Author: jao +;; Keywords: hardware + +;; This program is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see . + +;;; Code: + +(require 'dbus) + +(defvar jao-sleep-sleep-functions nil) +(defvar jao-sleep-awake-functions nil) + +(defvar jao-sleep--dbus-registration-object nil) + +(defun jao-sleep--dbus-sleep-handler (sleep-start) + (condition-case nil + (if sleep-start + (progn (message "Running on sleep functions") + (run-hooks 'jao-sleep-sleep-functions)) + (message "Running on awake functions") + (run-hooks 'jao-sleep-awake-functions)) + (error (message "There was an error running %s" sleep-start)))) + +;;;###autoload +(defun jao-sleep-dbus-register (&optional session-dbus) + "Register actions to take on sleep and on awake, using the system D-BUS." + (when (featurep 'dbusbind) + (setq jao-sleep--dbus-sleep-registration-object + (dbus-register-signal (if session-dbus :session :system) + "org.freedesktop.login1" + "/org/freedesktop/login1" + "org.freedesktop.login1.Manager" + "PrepareForSleep" + #'jao-sleep--dbus-sleep-handler)))) + +;;;###autoload +(defun jao-sleep-dbus-unregister () + (condition-case nil + (dbus-unregister-object jao-sleep--dbus-sleep-registration-object) + (wrong-type-argument nil))) + +(provide 'jao-sleep) +;;; jao-sleep.el ends here -- cgit v1.2.3