mode-line.lisp 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. (in-package :stumpwm)
  2. (setf *mode-line-position* :bottom)
  3. (defvar *mode-line-window-number* 10)
  4. (setf *group-format* "%t")
  5. (setf *mode-line-timeout* 2)
  6. (setf *TIME-MODELINE-STRING* "%a, %e %b %Y %k:%M")
  7. (setf *mode-line-pad-x* 10)
  8. (setf *mode-line-pad-y* 5)
  9. (setf *mode-line-border-width* 0)
  10. (defcommand mode-line-update () ()
  11. (setf *screen-mode-line-format*
  12. `("%g"
  13. ,(make-string 4 :initial-element #\space)
  14. ,'(:eval (let* ((group (current-group))
  15. (frame (tile-group-current-frame group))
  16. (windows (frame-sort-windows group frame))
  17. (windows-names
  18. (mapcar (lambda (window)
  19. (let ((wn (window-name window)))
  20. (format nil "~a:[~a]"
  21. (window-number window)
  22. (if (> (length wn) 10)
  23. (concat (subseq wn 0 10) "...")
  24. wn))))
  25. windows)))
  26. (if (> (length windows-names) 5)
  27. (format nil "(~a ...)" (join (take 5 windows-names)))
  28. (format nil "(~a)" (join windows-names)))))
  29. ,(make-string 4 :initial-element #\space)
  30. "^>"
  31. ;; TODO: Move to mjru.lisp
  32. ;; ,@(if (or (equal *mjru-hms-current-stack* "")
  33. ;; (equal *covid-19-count* ""))
  34. ;; '()
  35. ;; (list (make-string 4 :initial-element #\space)))
  36. ;; TODO: password-store-show
  37. ;; ,@(if (free-time?)
  38. ;; (if (equal *covid-19-count* "")
  39. ;; '()
  40. ;; (list '(:eval (format nil "COVID-19: ~a"
  41. ;; (let ((count (split-string *covid-19-count* '(#\:))))
  42. ;; (join (list (first count)
  43. ;; (format nil "^[^B^2*~a^]" (third count))
  44. ;; (format nil "^[^B^1*~a^]" (second count)))
  45. ;; #\:))))))
  46. ;; (if (equal *mjru-hms-current-stack* "")
  47. ;; '()
  48. ;; (list '(:eval (format nil "stack: ~a" *mjru-hms-current-stack*)))))
  49. ,@(if (and *imap-recent* (not (= *imap-recent* 0)))
  50. (list (make-string 4 :initial-element #\space))
  51. '())
  52. ,@(if (and *imap-recent* (not (= *imap-recent* 0)))
  53. (list '(:eval (format nil "INBOX: ~a" *imap-recent*)))
  54. '())
  55. ;; ,(make-string 4 :initial-element #\space)
  56. ;; ,'(:eval (kubectl-current-context *kubernetes-current-cluster* t))
  57. ,@(if (mountpoint-free? "/srv")
  58. (list (make-string 4 :initial-element #\space))
  59. '())
  60. ,@(if (mountpoint-free? "/srv")
  61. (list '(:eval (format nil "/srv: ~a" *disk-free-srv-counter*)))
  62. '())
  63. ,@(if (mountpoint-free? "/")
  64. (list (make-string 4 :initial-element #\space))
  65. '())
  66. ,@(if (mountpoint-free? "/")
  67. (list '(:eval (format nil "/: ~a" *disk-free-root-counter*)))
  68. '())
  69. ;; ,(make-string 4 :initial-element #\space)
  70. ;; ,'(:eval (fmt-temp-current (temp-current) t))
  71. ,(make-string 4 :initial-element #\space)
  72. ,'(:eval (fmt-mem-available (mem-usage) t))
  73. ,@(if (string-equal *mjru-tapvpn-ip* "")
  74. '()
  75. (list (make-string 4 :initial-element #\space)))
  76. ,@(if (string-equal *mjru-tapvpn-ip* "")
  77. '()
  78. (list '(:eval (format nil "VPN 1: ~a" *mjru-tapvpn-ip*))))
  79. ,(make-string 4 :initial-element #\space)
  80. "%d"
  81. ,(make-string 4 :initial-element #\space))))
  82. (mode-line-update)
  83. (mapcar (lambda (func)
  84. (add-hook *start-hook* func))
  85. (list (lambda ()
  86. ;; Get VPN IP address and set it to *mjru-tapvpn-ip* variable.
  87. (sb-thread:make-thread
  88. (lambda ()
  89. (loop while t do
  90. (progn (mjru-ip-address-vpn-update) (sleep 10))))
  91. :name "mjru-ip-address-vpn-update"))
  92. ;; TODO: Move to mjru.lisp
  93. ;; (lambda () (sb-thread:make-thread
  94. ;; (lambda ()
  95. ;; (loop while t do
  96. ;; (progn (mjru-hms-current-stack-update) (sleep 10))))
  97. ;; :name "mjru-hms-current-stack-update"))
  98. (lambda ()
  99. ;; (sb-thread:make-thread ||#
  100. ;; (lambda () ||#
  101. ;; (loop while t do ||#
  102. ;; (progn (if (gpg-key-opened? (concat (getenv "HOME") ||#
  103. ;; "/.password-store/localhost/imap/oleg.gpg")) ||#
  104. ;; (imap-update-recent-count) ||#
  105. ;; (setq *imap-recent* nil)) ||#
  106. ;; (sleep 60)))) ||#
  107. ;; :name "imap-update-recent-count") ||#
  108. (sb-thread:make-thread
  109. (lambda ()
  110. (loop while t do
  111. (progn
  112. (disk-free-srv-update-counter)
  113. (sleep 60))))
  114. :name "disk-free-srv-update-counter")
  115. (sb-thread:make-thread
  116. (lambda ()
  117. (loop while t do
  118. (progn
  119. (disk-free-root-update-counter)
  120. (sleep 60))))
  121. :name "disk-free-root-update-counter")
  122. ;; (sb-thread:make-thread
  123. ;; (lambda ()
  124. ;; (loop while t do
  125. ;; (progn
  126. ;; (kubernetes-update-current-cluster)
  127. ;; (sleep 60))))
  128. ;; :name "mode-line-kubernetes-current-cluster")
  129. ;; (sb-thread:make-thread
  130. ;; (lambda ()
  131. ;; (kubernetes-update-current-cluster-inotify))
  132. ;; :name "mode-line-kubernetes-current-cluster-inotify")
  133. ;; (sb-thread:make-thread
  134. ;; (lambda ()
  135. ;; (loop while t do
  136. ;; (progn
  137. ;; (run-shell-command "notmuch new")
  138. ;; (mode-line-update)
  139. ;; (sleep (* 60 60)))))
  140. ;; :name "notmuch")
  141. (sb-thread:make-thread
  142. (lambda ()
  143. (loop while t do
  144. (progn
  145. (covid-19-update-count)
  146. (sleep (* (* 60 60) 6)))))
  147. :name "covid-19"))))
  148. (defcommand mode-line-start-programs () ()
  149. (flet ((all-start-programs ()
  150. (filter (lambda (str)
  151. (uiop/utility:string-suffix-p str "-start-programs"))
  152. (all-commands))))
  153. (run-commands (first (filter (lambda (str)
  154. (string-contains (write-to-string (group-number (current-group))) str))
  155. (all-start-programs))))))
  156. (defvar *brightness* 20)
  157. ;; See events.lisp in StumpWM source.
  158. (setq *mode-line-click-hook*
  159. (list (lambda (mode-line button x y)
  160. (case button
  161. ((1) (mode-line-start-programs))
  162. ((2) (volume-toggle))
  163. ((3) (cond ((> x (- (screen-width (group-screen (current-group))) 30))
  164. (pulseaudio-toggle-ladspa))
  165. (t
  166. (delete-window))))
  167. ((4) (cond ((> x (- (screen-width (group-screen (current-group))) 30))
  168. (volume-increase))
  169. ((> x (- (screen-width (group-screen (current-group))) 120))
  170. (windows-volume-increase))
  171. ((> x 200)
  172. (prev-in-frame))
  173. ((> x 180)
  174. (let ((percentage (+ *brightness* 5)))
  175. (brightness percentage)
  176. (setq *brightness* percentage)))
  177. (t
  178. (gprev))))
  179. ((5) (cond ((> x (- (screen-width (group-screen (current-group))) 30))
  180. (volume-decrease))
  181. ((> x (- (screen-width (group-screen (current-group))) 120))
  182. (windows-volume-decrease))
  183. ((> x 200)
  184. (next-in-frame))
  185. ((> x 180)
  186. (let ((percentage (- *brightness* 5)))
  187. (brightness percentage)
  188. (setq *brightness* percentage)))
  189. (t
  190. (gnext))))
  191. ((8) (volume-decrease))
  192. ((9) (volume-increase))))))