mode-line.lisp 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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. ;; ,'(:eval (format nil "VOL: ~a" *volume-current*))
  81. ,(make-string 4 :initial-element #\space)
  82. "%d"
  83. ,(make-string 4 :initial-element #\space))))
  84. (mode-line-update)
  85. (mapcar (lambda (func)
  86. (add-hook *start-hook* func))
  87. (list (lambda ()
  88. ;; Get VPN IP address and set it to *mjru-tapvpn-ip* variable.
  89. (sb-thread:make-thread
  90. (lambda ()
  91. (loop while t do
  92. (progn (mjru-ip-address-vpn-update) (sleep 10))))
  93. :name "mjru-ip-address-vpn-update"))
  94. ;; TODO: Move to mjru.lisp
  95. ;; (lambda () (sb-thread:make-thread
  96. ;; (lambda ()
  97. ;; (loop while t do
  98. ;; (progn (mjru-hms-current-stack-update) (sleep 10))))
  99. ;; :name "mjru-hms-current-stack-update"))
  100. (lambda ()
  101. ;; (sb-thread:make-thread ||#
  102. ;; (lambda () ||#
  103. ;; (loop while t do ||#
  104. ;; (progn (if (gpg-key-opened? (concat (getenv "HOME") ||#
  105. ;; "/.password-store/localhost/imap/oleg.gpg")) ||#
  106. ;; (imap-update-recent-count) ||#
  107. ;; (setq *imap-recent* nil)) ||#
  108. ;; (sleep 60)))) ||#
  109. ;; :name "imap-update-recent-count") ||#
  110. (sb-thread:make-thread
  111. (lambda ()
  112. (loop while t do
  113. (progn
  114. (disk-free-srv-update-counter)
  115. (sleep 60))))
  116. :name "disk-free-srv-update-counter")
  117. (sb-thread:make-thread
  118. (lambda ()
  119. (loop while t do
  120. (progn
  121. (disk-free-root-update-counter)
  122. (sleep 60))))
  123. :name "disk-free-root-update-counter")
  124. (sb-thread:make-thread
  125. (lambda ()
  126. (loop while t do
  127. (progn
  128. (kubernetes-update-current-cluster)
  129. (sleep 60))))
  130. :name "mode-line-kubernetes-current-cluster")
  131. (sb-thread:make-thread
  132. (lambda ()
  133. (kubernetes-update-current-cluster-inotify))
  134. :name "mode-line-kubernetes-current-cluster-inotify")
  135. ;; (sb-thread:make-thread
  136. ;; (lambda ()
  137. ;; (loop while t do
  138. ;; (progn
  139. ;; (run-shell-command "notmuch new")
  140. ;; (mode-line-update)
  141. ;; (sleep (* 60 60)))))
  142. ;; :name "notmuch")
  143. (sb-thread:make-thread
  144. (lambda ()
  145. (loop while t do
  146. (progn
  147. (covid-19-update-count)
  148. (sleep (* (* 60 60) 6)))))
  149. :name "covid-19"))))
  150. (defcommand mode-line-start-programs () ()
  151. (flet ((all-start-programs ()
  152. (filter (lambda (str)
  153. (uiop/utility:string-suffix-p str "-start-programs"))
  154. (all-commands))))
  155. (run-commands (first (filter (lambda (str)
  156. (string-contains (write-to-string (group-number (current-group))) str))
  157. (all-start-programs))))))
  158. (defvar *brightness* 20)
  159. ;; See events.lisp in StumpWM source.
  160. (setq *mode-line-click-hook*
  161. (list (lambda (mode-line button x y)
  162. (case button
  163. ((1) (mode-line-start-programs))
  164. ((2) (volume-toggle))
  165. ((3) (delete-window))
  166. ((4) (cond ((> x (- (screen-width (group-screen (current-group))) 30))
  167. (volume-increase))
  168. ((> x 200)
  169. (prev-in-frame))
  170. ((> x 180)
  171. (let ((percentage (+ *brightness* 5)))
  172. (brightness percentage)
  173. (setq *brightness* percentage)))
  174. (t
  175. (gprev))))
  176. ((5) (cond ((> x (- (screen-width (group-screen (current-group))) 30))
  177. (volume-decrease))
  178. ((> x 200)
  179. (next-in-frame))
  180. ((> x 180)
  181. (let ((percentage (- *brightness* 5)))
  182. (brightness percentage)
  183. (setq *brightness* percentage)))
  184. (t
  185. (gnext))))
  186. ((8) (volume-decrease))
  187. ((9) (volume-increase))))))