summaryrefslogtreecommitdiff
path: root/src/wasp-overlay.el
blob: e902eb3db7e93fb7a9816396c2e31925e9c67feb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
;;; wasp-overlay --- Fullscreen overlay -*- lexical-binding: t; -*-
;;; Commentary:
;;; Code:

(require 'wasp-utils)
(require 'wasp-bus)

(defun w/overlay-shader (user shader)
  "Set the overlay shader to SHADER by USER."
  (w/pub '(avatar overlay shader)
    (list (w/encode-string user) (w/encode-string shader))))

(defun w/overlay-chat (msg)
  "Update the overlay about chat MSG."
  (w/pub '(avatar overlay chat)
    (list
      (w/encode-string (w/. user msg))
      (w/encode-string (w/. text msg))
      (format "%s" (w/unix-time))
      (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/pub '(avatar overlay muzak) (list (w/encode-string user))))

(defun w/overlay-muzak-clear ()
  "Tell the overlay that there is no Muzak song playing."
  (w/pub '(avatar overlay muzak clear) (list)))

(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-process)))
    (when-let* ((pos (window-absolute-pixel-position)))
      (when (not (equal pos w/overlay-last-cursor))
        (setf w/overlay-last-cursor pos)
        (w/pub '(avatar overlay cursor) (list (car pos) (cdr pos)))))))
(add-hook 'post-command-hook #'w/overlay-update-cursor)

(defun w/overlay-emacs ()
  "Update the overlay with miscellaneous data from Emacs."
  (w/pub '(avatar overlay emacs)
    (list
      (w/get-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/pub '(avatar automata spawn)
    (list
      (w/encode-string s)
      (w/encode-string user)
      (w/encode-string (or color (w/random-color))))))

(provide 'wasp-overlay)
;;; wasp-overlay.el ends here