;;; wasp-overlay --- Fullscreen overlay -*- lexical-binding: t; -*- ;;; Commentary: ;;; Code: (require 'wasp-utils) (require 'wasp-bus-binary) (defun w/overlay-toggle (effect) "Toggle EFFECT in the overlay." (w/binary-pub "overlay toggle" effect)) (defun w/overlay-toggle-set (effect) "Turn on EFFECT in the overlay." (w/binary-pub "overlay toggle set" effect)) (defun w/overlay-toggle-unset (effect) "Turn off EFFECT in the overlay." (w/binary-pub "overlay toggle unset" effect)) (defun w/overlay-shader (user shader) "Set the overlay shader to SHADER by USER." (w/binary-pub "overlay shader" (s-concat (w/bus-binary-build-length-prefixed user) (w/bus-binary-build-length-prefixed shader)))) (defun w/overlay-chat (msg) "Update the overlay about chat MSG." ;; (w/binary-pub "overlay chat" ;; (s-concat ;; (w/bus-binary-build-length-prefixed (w/. user msg)) ;; (w/bus-binary-build-length-prefixed (w/. text msg)) ;; (w/bus-binary-build-length-prefixed (format "%s" (w/unix-time))) ;; (w/bus-binary-build-length-prefixed (format "%s" (or (w/. biblicality msg) 0.0))))) ) (defun w/overlay-muzak (user song) "Update the overlay about Muzak SONG played by USER." (ignore song) (w/binary-pub "overlay info credits music" user)) (defun w/overlay-muzak-clear () "Tell the overlay that there is no Muzak song playing." (w/binary-pub "overlay info credits music clear" "")) (defvar w/overlay-last-cursor nil) (defun w/overlay-update-cursor () "Inform the overlay about the current cursor position." (when (and (process-live-p (get-process w/bus-binary-process))) (when-let* ((pos (window-absolute-pixel-position))) (when (not (equal pos w/overlay-last-cursor)) (setf w/overlay-last-cursor pos) (w/binary-pub "overlay info emacs cursor" (s-concat (w/bus-binary-build-length-prefixed (format "%s" (car pos))) (w/bus-binary-build-length-prefixed (format "%s" (cdr pos))))))))) (add-hook 'post-command-hook #'w/overlay-update-cursor) (defun w/overlay-emacs () "Update the overlay with miscellaneous data from Emacs." ;; (w/binary-pub "overlay info emacs" (w/bus-binary-build-int32le (w/heartrate))) ) (defun w/overlay-automata (user s &optional color) "Send a cellular automata S from USER in RLE format to the overlay. Optionally, make the cells be COLOR." (w/binary-pub "overlay automata spawn" (s-concat (w/bus-binary-build-length-prefixed s) (w/bus-binary-build-length-prefixed user) (w/bus-binary-build-int32le (string-to-number (s-chop-prefix "#" (or color (w/random-color))) 16))))) ;;;; Clippy (defun w/overlay-clippy-animate (anim) "Set the Clippy animation to ANIM." (w/binary-pub "overlay clippy animate" (s-concat (w/bus-binary-build-length-prefixed anim)))) (defun w/overlay-clippy-border (border) "Set the Clippy border state to BORDER." (w/binary-pub (if border "overlay clippy border on" "overlay clippy border off") "")) (cl-defstruct (w/overlay-clippy-event (:constructor w/overlay-clippy-event-new)) timestamp type) (define-derived-mode w/overlay-clippy-mode special-mode "Karl Klammer" "Major mode for displaying Clippy dialogue." :group 'wasp (setq mode-line-format nil)) (defface w/overlay-clippy-face '((t :foreground "black" :font "Terminus (TTF):antialias=false:hinting=false:pixelsize=24" )) "Face for Clippy dialogue." :group 'wasp) (defconst w/overlay-clippy-frame-buffer-name " *clippy-dialogue*") (defvar w/overlay-clippy-frame-background-color "#ffffcc") (defvar w/overlay-clippy-frame nil) (defvar w/overlay-clippy-last-event nil) (defvar w/overlay-clippy-speech-timer nil) (defun w/overlay-clippy-frame-buffer () "Return the buffer used to display Clippy dialogue." (let ((name w/overlay-clippy-frame-buffer-name)) (unless (get-buffer name) (with-current-buffer (get-buffer-create name) (w/overlay-clippy-mode))) (get-buffer name))) (defun w/overlay-clippy-frame-create () "Build a frame for displaying completion candidates." (when (framep w/overlay-clippy-frame) (delete-frame w/overlay-clippy-frame)) (setf w/overlay-clippy-frame (make-frame (append `((name . "clippy") (unsplittable . t) (undecorated . t) (no-accept-focus . t) (no-focus-on-map . t) (override-redirect . t) (user-size . t) (width . 25) (height . 8) (user-position . t) (left . 1600) (top . 550) (default-minibuffer-frame . ,(selected-frame)) (minibuffer . nil) (left-fringe . 0) (right-fringe . 0) (cursor-type . nil) (background-color . ,w/overlay-clippy-frame-background-color))))) (make-frame-invisible w/overlay-clippy-frame) (let ((window (frame-selected-window w/overlay-clippy-frame))) (set-window-buffer window (w/overlay-clippy-frame-buffer)))) (w/overlay-clippy-frame-create) (defun w/overlay-clippy-clear () "Clear the Clippy buffer." (when w/overlay-clippy-frame (modify-frame-parameters w/overlay-clippy-frame `((background-color . ,w/overlay-clippy-frame-background-color)))) (with-current-buffer (w/overlay-clippy-frame-buffer) (let ((inhibit-read-only t)) (erase-buffer)))) (defun w/overlay-clippy-write (msg) "Write MSG to the Clippy buffer." (when w/overlay-clippy-frame (modify-frame-parameters w/overlay-clippy-frame `((background-color . ,w/overlay-clippy-frame-background-color)))) (let ((window (frame-selected-window w/overlay-clippy-frame))) (set-window-buffer window (w/overlay-clippy-frame-buffer))) (with-current-buffer (w/overlay-clippy-frame-buffer) (let ((inhibit-read-only t)) (w/write-line msg 'w/overlay-clippy-face)))) (defun w/overlay-clippy-say (msg) "Have Clippy say MSG." (w/overlay-clippy-clear) (w/overlay-clippy-write msg) (w/overlay-clippy-border t) (w/show-frame w/overlay-clippy-frame t) (raise-frame w/overlay-clippy-frame) (w/overlay-clippy-animate "EXPLAIN") (setf w/overlay-clippy-speech-timer 10)) (defun w/overlay-clippy-check-events () "Check for events that Clippy should respond to." ) (defun w/overlay-clippy-update () "Update Clippy." (when w/overlay-clippy-speech-timer (cl-decf w/overlay-clippy-speech-timer) (when (<= w/overlay-clippy-speech-timer 0) (w/overlay-clippy-border nil) (w/show-frame w/overlay-clippy-frame nil) (setf w/overlay-clippy-speech-timer nil))) (w/overlay-clippy-check-events)) (defvar w/overlay-clippy-timer nil) (defun w/overlay-clippy-timer-run () "Run the gizmo update timer." (when w/overlay-clippy-timer (cancel-timer w/overlay-clippy-timer)) (w/overlay-clippy-update) (setq w/overlay-clippy-timer (run-with-timer 1 nil #'w/overlay-clippy-timer-run))) (provide 'wasp-overlay) ;;; wasp-overlay.el ends here