summaryrefslogtreecommitdiffhomepage
path: root/attic/orgs/misc.el
blob: b56c5df94c296b5dcd8cc58b30faf0082b51ad82 (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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
;;;; sway
(defun jao-swaymsg (msg)
  (shell-command (format "swaymsg '%s' >/dev/null" msg)))

(defmacro jao-def-swaymsg (name msg)
  `(defun ,(intern (format "jao-sway-%s" name)) ()
     (interactive)
     (jao-swaymsg ,msg)))
(jao-def-swaymsg firefox "[app_id=firefox] focus")

(defvar jao-sway-enabled
  (and (eq window-system 'pgtk) (not jao-xmonad-enabled)))

(defun jao-sway-set-wallpaper (f)
  (jao-swaymsg (format "output * bg %s fill" f))
  (make-symbolic-link f "~/.wallpaper.sway" t))

(defun jao-sway-run-or-focus (cmd &optional ws)
  (if (jao-shell-running-p "firefox")
      (jao-swaymsg (format "[app_id=%s] focus" cmd))
    (jao-swaymsg (format "workspace %s" (or ws 2)))
    (start-process-shell-command cmd nil cmd)))

(defun jao-sway-run-or-focus-tidal ()
  (interactive)
  (if (jao-shell-running-p "tidal-hifi")
      (jao-swaymsg "[app_id=tidal-hifi] scratchpad show")
    (start-process-shell-command "tidal-hifi" nil "tidal-hifi &")
    (jao-sway-run-or-focus-tidal)))

(defun jao-sway-run-or-focus-firefox ()
  (interactive)
  (jao-sway-run-or-focus "firefox"))

(defun jao-sway-enable ()
  (setq jao-browse-doc-use-emacs-p t)
  (setq jao-wallpaper-random-wake nil)
  (jao-trisect)
  (jao-set-transparency 85)
  (jao-themes-setup)
  ;; (display-time-mode 1)
  (global-set-key (kbd "s-f") #'jao-sway-run-or-focus-firefox)
  (defalias 'jao-streaming-list #'jao-sway-run-or-focus-tidal)
  (message "Welcome to sway"))

(when jao-sway-enabled
  (defalias 'x-change-window-property #'ignore)
  (add-hook 'after-init-hook #'jao-sway-enable))

;;;; time display
(setq display-time-world-list
      '(("Europe/Paris" "Barcelona")
        ("America/Los_Angeles" "Los Angeles")
        ("America/New_York" "New York")
        ("Europe/London" "London")
        ("Asia/Calcutta" "Bangalore")
        ("Asia/Tokyo" "Tokyo")))

(defun jao-time--pdt-hour ()
  (jao-time-at-zone "%H" "America/Los_Angeles"))

(defun jao-time--chicago-hour ()
  (jao-time-at-zone "%H" "America/Chicago"))

(defun jao-time-at-zone (format zone)
  (set-time-zone-rule zone)
  (prog1 (format-time-string format)
    (set-time-zone-rule nil)))

(defun jao-time-echo-la-time ()
  (interactive)
  (message (jao-time-at-zone "LA %H:%M" "America/Los_Angeles")))

(defun jao-time-echo-times ()
  (interactive)
  (let ((msg (format "%s (%s)"
                     (format-time-string "%a, %e %B - %H:%M")
                     (jao-time-at-zone "%H:%M" "America/Los_Angeles"))))
    (jao-notify msg "" (jao-data-file "clock-world-icon.png"))))

(defun jao-time-to-epoch (&optional s)
  "Transform a time string to an epoch integer in milliseconds."
  (interactive)
  (let ((s (or s (read-string "Time string: " (thing-at-point 'string)))))
    (message "%s = %s"
             s
             (round (* 1000 (time-to-seconds (parse-time-string s)))))))

(defun jao-epoch-to-time (&optional v)
  "Transform an epoch, given in milliseconds, to a time string."
  (interactive)
  (let ((v (or v (read-number "Milliseconds: " (thing-at-point 'number)))))
    (message "%s = %s" v
             (format-time-string "%Y-%m-%d %H:%M:%S"
                                 (seconds-to-time (/ v 1000.0))))))