contrib/toolbar.lisp: Add memory, cpu and battery usage module with a poll methode.
[clfswm.git] / contrib / toolbar.lisp
blobbcd1f62b257bb9f27b9522aebc23cf256a8d2b7d
1 ;;; --------------------------------------------------------------------------
2 ;;; CLFSWM - FullScreen Window Manager
3 ;;;
4 ;;; --------------------------------------------------------------------------
5 ;;; Documentation: Toolbar
6 ;;; --------------------------------------------------------------------------
7 ;;;
8 ;;; (C) 2012 Philippe Brochard <pbrochard@common-lisp.net>
9 ;;;
10 ;;; This program is free software; you can redistribute it and/or modify
11 ;;; it under the terms of the GNU General Public License as published by
12 ;;; the Free Software Foundation; either version 3 of the License, or
13 ;;; (at your option) any later version.
14 ;;;
15 ;;; This program is distributed in the hope that it will be useful,
16 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;;; GNU General Public License for more details.
19 ;;;
20 ;;; You should have received a copy of the GNU General Public License
21 ;;; along with this program; if not, write to the Free Software
22 ;;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 ;;;
24 ;;; Documentation: If you want to use this file, just add this line in
25 ;;; your configuration file:
26 ;;;
27 ;;; (load-contrib "toolbar.lisp")
28 ;;;
29 ;;; You can add a toolbar with the function add-toolbar in your configuration
30 ;;; file. You can obtain modules list with the list-toolbar-modules function.
31 ;;;
32 ;;; For convenience, here is the add-toolbar documentation:
33 ;;;
34 ;;; add-toolbar (root-x root-y direction size placement modules
35 ;;; &key (autohide *toolbar-default-autohide*)
36 ;;; (thickness *toolbar-default-thickness*)
37 ;;; (refresh-delay *toolbar-default-refresh-delay*)
38 ;;; (border-size *toolbar-default-border-size*))
39 ;;; "Add a new toolbar.
40 ;;; root-x, root-y: root coordinates or if root-y is nil, root-x is the nth root in root-list.
41 ;;; direction: one of :horiz or :vert
42 ;;; placement: same argument as with-placement macro
43 ;;; modules: list of modules: a list of module name, position in percent and arguments.
44 ;;; 0%=left/up <-> 100%=right/down.
45 ;;; Example: '((clock 1) (label 50 \"My label\") (clickable-clock 90))
46 ;;; size: toolbar size in percent of root size
47 ;;; thickness: toolbar height for horizontal toolbar or width for vertical one
48 ;;; autohide: one of nil, :click, or :motion
49 ;;; refresh-delay: refresh delay for toolbar in seconds
50 ;;; border-size: toolbar window border size"
51 ;;;
52 ;;; Here are some examples:
53 ;;; (load-contrib "toolbar.lisp")
54 ;;;
55 ;;; ;; Add an horizontal toolbar on root at coordinates 0,0 pixels
56 ;;; ;; with default modules
57 ;;;
58 ;;; (add-toolbar 0 0 :horiz 80 'top-middle-root-placement *default-toolbar*)
59 ;;;
60 ;;;
61 ;;; ;; Add an horizontal toolbar on root at coordinates 0,0 pixels
62 ;;;
63 ;;; (add-toolbar 0 0 :horiz 90 'top-middle-root-placement
64 ;;; '((clock 1) (label 50 "Plop") (clock-second 25) (clickable-clock 99))
65 ;;; :autohide :click
66 ;;; :refresh-delay 1)
67 ;;;
68 ;;;
69 ;;; ;; Add an horizontal toolbar on root at coordinates 0,0 pixels
70 ;;;
71 ;;; (add-toolbar 0 0 :horiz 70 'bottom-middle-root-placement '((clock 1) (label 50 "Paf) (clock 99))
72 ;;; :autohide :motion)
73 ;;;
74 ;;;
75 ;;; ;; Add a vertical toolbar on root 0
76 ;;;
77 ;;; (add-toolbar 0 nil :vert 60 'middle-left-root-placement '((clock 1) (label 50 "My label") (clock 90)))
78 ;;;
79 ;;;
80 ;;; ;; Add a vertical toolbar on root 1
81 ;;;
82 ;;; (add-toolbar 1 nil :vert 70 'bottom-right-root-placement '((clock 1) (label 50) (clickable-clock 99)))
83 ;;; --------------------------------------------------------------------------
85 (in-package :clfswm)
87 (format t "Loading Toolbar code... ")
89 (defstruct toolbar root-x root-y root direction size thickness placement refresh-delay
90 autohide modules clickable hide-state font window gc border-size)
92 (defstruct toolbar-module name pos display-fun click-fun args rect)
94 (defparameter *toolbar-list* nil)
95 (defparameter *toolbar-module-list* nil)
97 (defconfig *default-toolbar* '((clfswm-menu 1)
98 (system-usage 90)
99 (clickable-clock 99))
100 'Toolbar "Default toolbar modules")
103 ;;; CONFIG - Toolbar window string colors
104 (defconfig *toolbar-window-font-string* *default-font-string*
105 'Toolbar "Toolbar window font string")
106 (defconfig *toolbar-window-background* "black"
107 'Toolbar "Toolbar Window background color")
108 (defconfig *toolbar-window-foreground* "green"
109 'Toolbar "Toolbar Window foreground color")
110 (defconfig *toolbar-window-border* "red"
111 'Toolbar "Toolbar Window border color")
112 (defconfig *toolbar-default-border-size* 0
113 'Toolbar "Toolbar Window border size")
114 (defconfig *toolbar-window-transparency* *default-transparency*
115 'Toolbar "Toolbar window background transparency")
116 (defconfig *toolbar-default-thickness* 20
117 'Toolbar "Toolbar default thickness")
118 (defconfig *toolbar-default-refresh-delay* 30
119 'Toolbar "Toolbar default refresh delay")
120 (defconfig *toolbar-default-autohide* nil
121 'Toolbar "Toolbar default autohide value")
122 (defconfig *toolbar-sensibility* 3
123 'Toolbar "Toolbar sensibility in pixels")
125 (defconfig *toolbar-window-placement* 'top-left-placement
126 'Placement "Toolbar window placement")
128 (defun toolbar-symbol-fun (name &optional (type 'display))
129 (create-symbol-in-package :clfswm 'toolbar- name '-module- type))
131 (defun toolbar-adjust-root-size (toolbar)
132 (unless (toolbar-autohide toolbar)
133 (let ((root (toolbar-root toolbar))
134 (placement-name (symbol-name (toolbar-placement toolbar)))
135 (thickness (+ (toolbar-thickness toolbar) (* 2 (toolbar-border-size toolbar)))))
136 (when (root-p root)
137 (case (toolbar-direction toolbar)
138 (:horiz (cond ((search "TOP" placement-name)
139 (incf (root-y root) thickness)
140 (decf (root-h root) thickness))
141 ((search "BOTTOM" placement-name)
142 (decf (root-h root) thickness))))
143 (t (cond ((search "LEFT" placement-name)
144 (incf (root-x root) thickness)
145 (decf (root-w root) thickness))
146 ((search "RIGHT" placement-name)
147 (decf (root-w root) thickness)))))))))
150 (defun toolbar-draw-text (toolbar pos1 pos2 text)
151 "pos1: percent of toolbar, pos2: pixels in toolbar"
152 (labels ((horiz-text ()
153 (let* ((height (- (xlib:font-ascent (toolbar-font toolbar)) (xlib:font-descent (toolbar-font toolbar))))
154 (dy (truncate (+ pos2 (/ height 2))))
155 (width (xlib:text-width (toolbar-font toolbar) text))
156 (pos (truncate (/ (* (- (xlib:drawable-width (toolbar-window toolbar)) width) pos1) 100))))
157 (xlib:draw-glyphs *pixmap-buffer* (toolbar-gc toolbar) pos dy text)
158 (values (+ pos (xlib:drawable-x (toolbar-window toolbar)))
159 (xlib:drawable-y (toolbar-window toolbar))
160 width
161 (xlib:drawable-height (toolbar-window toolbar)))))
162 (vert-text ()
163 (let* ((width (xlib:max-char-width (toolbar-font toolbar)))
164 (dx (truncate (- pos2 (/ width 2))))
165 (dpos (xlib:max-char-ascent (toolbar-font toolbar)))
166 (height (* dpos (length text)))
167 (pos (+ (truncate (/ (* (- (xlib:drawable-height (toolbar-window toolbar)) height
168 (xlib:max-char-descent (toolbar-font toolbar)))
169 pos1) 100))
170 (xlib:font-ascent (toolbar-font toolbar)))))
171 (loop for c across text
172 for i from 0
173 do (xlib:draw-glyphs *pixmap-buffer* (toolbar-gc toolbar) dx (+ pos (* i dpos)) (string c)))
174 (values (xlib:drawable-x (toolbar-window toolbar))
175 (+ (- pos dpos) (xlib:drawable-y (toolbar-window toolbar)))
176 (xlib:drawable-width (toolbar-window toolbar))
177 height))))
178 (case (toolbar-direction toolbar)
179 (:horiz (horiz-text))
180 (:vert (vert-text)))))
183 (defun toolbar-module-text (toolbar module formatter &rest text)
184 "Print a formatted text at module position centered in toolbar"
185 (toolbar-draw-text toolbar (toolbar-module-pos module) (/ *toolbar-default-thickness* 2)
186 (apply #'format nil formatter text)))
190 (defun refresh-toolbar (toolbar)
191 (unless (toolbar-hide-state toolbar)
192 (add-timer (toolbar-refresh-delay toolbar)
193 (lambda ()
194 (refresh-toolbar toolbar))
195 :refresh-toolbar)
196 (clear-pixmap-buffer (toolbar-window toolbar) (toolbar-gc toolbar))
197 (dolist (module (toolbar-modules toolbar))
198 (when (fboundp (toolbar-module-display-fun module))
199 (apply (toolbar-module-display-fun module) toolbar module (toolbar-module-args module))))
200 (copy-pixmap-buffer (toolbar-window toolbar) (toolbar-gc toolbar))))
202 (defun toolbar-in-sensibility-zone-p (toolbar root-x root-y)
203 (let* ((tb-win (toolbar-window toolbar))
204 (win-x (xlib:drawable-x tb-win))
205 (win-y (xlib:drawable-y tb-win))
206 (width (xlib:drawable-width tb-win))
207 (height (xlib:drawable-height tb-win))
208 (tb-dir (toolbar-direction toolbar) )
209 (placement-name (symbol-name (toolbar-placement toolbar))))
210 (or (and (equal tb-dir :horiz) (search "TOP" placement-name)
211 (<= root-y win-y (+ root-y *toolbar-sensibility*))
212 (<= win-x root-x (+ win-x width)) (toolbar-autohide toolbar))
213 (and (equal tb-dir :horiz) (search "BOTTOM" placement-name)
214 (<= (+ win-y height (- *toolbar-sensibility*)) root-y (+ win-y height))
215 (<= win-x root-x (+ win-x width)) (toolbar-autohide toolbar))
216 (and (equal tb-dir :vert) (search "LEFT" placement-name)
217 (<= root-x win-x (+ root-x *toolbar-sensibility*))
218 (<= win-y root-y (+ win-y height)) (toolbar-autohide toolbar))
219 (and (equal tb-dir :vert) (search "RIGHT" placement-name)
220 (<= (+ win-x width (- *toolbar-sensibility*)) root-x (+ win-x width))
221 (<= win-y root-y (+ win-y height)) (toolbar-autohide toolbar)))))
223 (use-event-hook :exposure)
224 (use-event-hook :button-press)
225 (use-event-hook :motion-notify)
226 (use-event-hook :leave-notify)
229 (defun toolbar-add-exposure-hook (toolbar)
230 (define-event-hook :exposure (window)
231 (when (and (xlib:window-p window) (xlib:window-equal (toolbar-window toolbar) window))
232 (refresh-toolbar toolbar))))
234 (defun toolbar-add-hide-button-press-hook (toolbar)
235 (define-event-hook :button-press (code root-x root-y)
236 (when (= code 1)
237 (let* ((tb-win (toolbar-window toolbar)))
238 (when (toolbar-in-sensibility-zone-p toolbar root-x root-y)
239 (if (toolbar-hide-state toolbar)
240 (progn
241 (setf (toolbar-hide-state toolbar) nil)
242 (map-window tb-win)
243 (raise-window tb-win)
244 (refresh-toolbar toolbar))
245 (progn
246 (hide-window tb-win)
247 (setf (toolbar-hide-state toolbar) t)))
248 (wait-mouse-button-release)
249 (stop-button-event)
250 (exit-handle-event))))))
252 (defun toolbar-add-hide-motion-hook (toolbar)
253 (define-event-hook :motion-notify (root-x root-y)
254 (unless (compress-motion-notify)
255 (when (and (toolbar-hide-state toolbar)
256 (toolbar-in-sensibility-zone-p toolbar root-x root-y))
257 (map-window (toolbar-window toolbar))
258 (raise-window (toolbar-window toolbar))
259 (refresh-toolbar toolbar)
260 (setf (toolbar-hide-state toolbar) nil)
261 (exit-handle-event)))))
263 (defun toolbar-add-hide-leave-hook (toolbar)
264 (define-event-hook :leave-notify (root-x root-y)
265 (when (and (not (toolbar-hide-state toolbar))
266 (not (in-window (toolbar-window toolbar) root-x root-y)))
267 (hide-window (toolbar-window toolbar))
268 (setf (toolbar-hide-state toolbar) t)
269 (exit-handle-event))))
272 (defun toolbar-add-clickable-module-hook (toolbar)
273 (define-event-hook :button-press (code state root-x root-y)
274 (when (and (in-window (toolbar-window toolbar) root-x root-y)
275 (not (toolbar-hide-state toolbar)))
276 (dolist (module (toolbar-modules toolbar))
277 (when (and (in-rectangle root-x root-y (toolbar-module-rect module))
278 (fboundp (toolbar-module-click-fun module)))
279 (apply (toolbar-module-click-fun module) toolbar module code state
280 (toolbar-module-args module))
281 (stop-button-event)
282 (exit-handle-event))))))
285 (defun define-toolbar-hooks (toolbar)
286 (toolbar-add-exposure-hook toolbar)
287 (when (toolbar-clickable toolbar)
288 (toolbar-add-clickable-module-hook toolbar))
289 (case (toolbar-autohide toolbar)
290 (:click (toolbar-add-hide-button-press-hook toolbar))
291 (:motion (toolbar-add-hide-motion-hook toolbar)
292 (toolbar-add-hide-leave-hook toolbar))))
294 (defun set-clickable-toolbar (toolbar)
295 (dolist (module (toolbar-modules toolbar))
296 (when (fboundp (toolbar-module-click-fun module))
297 (setf (toolbar-clickable toolbar) t))))
301 (let ((windows-list nil))
302 (defun is-toolbar-window-p (win)
303 (and (xlib:window-p win) (member win windows-list :test 'xlib:window-equal)))
305 (defun close-toolbar (toolbar)
306 (erase-timer :refresh-toolbar-window)
307 (setf *never-managed-window-list*
308 (remove (list #'is-toolbar-window-p nil)
309 *never-managed-window-list* :test #'equal))
310 (awhen (toolbar-gc toolbar)
311 (xlib:free-gcontext it))
312 (awhen (toolbar-window toolbar)
313 (xlib:destroy-window it))
314 (awhen (toolbar-font toolbar)
315 (xlib:close-font it))
316 (xlib:display-finish-output *display*)
317 (setf (toolbar-window toolbar) nil
318 (toolbar-gc toolbar) nil
319 (toolbar-font toolbar) nil))
321 (defun open-toolbar (toolbar)
322 (let ((root (root (toolbar-root-x toolbar) (toolbar-root-y toolbar))))
323 (when (root-p root)
324 (setf (toolbar-root toolbar) root)
325 (let ((*get-current-root-fun* (lambda () root)))
326 (setf (toolbar-font toolbar) (xlib:open-font *display* *toolbar-window-font-string*))
327 (let* ((width (if (equal (toolbar-direction toolbar) :horiz)
328 (round (/ (* (root-w root) (toolbar-size toolbar)) 100))
329 (toolbar-thickness toolbar)))
330 (height (if (equal (toolbar-direction toolbar) :horiz)
331 (toolbar-thickness toolbar)
332 (round (/ (* (root-h root) (toolbar-size toolbar)) 100)))))
333 (with-placement ((toolbar-placement toolbar) x y width height (toolbar-border-size toolbar))
334 (setf (toolbar-window toolbar) (xlib:create-window :parent *root*
335 :x x
336 :y y
337 :width width
338 :height height
339 :background (get-color *toolbar-window-background*)
340 :border-width (toolbar-border-size toolbar)
341 :border (when (plusp (toolbar-border-size toolbar))
342 (get-color *toolbar-window-border*))
343 :colormap (xlib:screen-default-colormap *screen*)
344 :event-mask '(:exposure :key-press :leave-window
345 :pointer-motion))
346 (toolbar-gc toolbar) (xlib:create-gcontext :drawable (toolbar-window toolbar)
347 :foreground (get-color *toolbar-window-foreground*)
348 :background (get-color *toolbar-window-background*)
349 :font (toolbar-font toolbar)
350 :line-style :solid))
351 (push (toolbar-window toolbar) windows-list)
352 (setf (window-transparency (toolbar-window toolbar)) *toolbar-window-transparency*)
353 (push (list #'is-toolbar-window-p nil) *never-managed-window-list*)
354 (map-window (toolbar-window toolbar))
355 (raise-window (toolbar-window toolbar))
356 (refresh-toolbar toolbar)
357 (when (toolbar-autohide toolbar)
358 (hide-window (toolbar-window toolbar))
359 (setf (toolbar-hide-state toolbar) t))
360 (xlib:display-finish-output *display*)
361 (set-clickable-toolbar toolbar)
362 (define-toolbar-hooks toolbar))))))))
365 (defun open-all-toolbars ()
366 "Open all toolbars"
367 (dolist (toolbar *toolbar-list*)
368 (open-toolbar toolbar))
369 (dolist (toolbar *toolbar-list*)
370 (toolbar-adjust-root-size toolbar)))
372 (defun close-all-toolbars ()
373 (dolist (toolbar *toolbar-list*)
374 (close-toolbar toolbar)))
376 (defun create-toolbar-modules (modules)
377 (loop for mod in modules
378 collect (make-toolbar-module :name (first mod)
379 :pos (second mod)
380 :display-fun (toolbar-symbol-fun (first mod))
381 :click-fun (toolbar-symbol-fun (first mod) 'click)
382 :args (cddr mod)
383 :rect nil)))
386 (defun add-toolbar (root-x root-y direction size placement modules
387 &key (autohide *toolbar-default-autohide*)
388 (thickness *toolbar-default-thickness*)
389 (refresh-delay *toolbar-default-refresh-delay*)
390 (border-size *toolbar-default-border-size*))
391 "Add a new toolbar.
392 root-x, root-y: root coordinates or if root-y is nil, root-x is the nth root in root-list.
393 direction: one of :horiz or :vert
394 placement: same argument as with-placement macro
395 modules: list of modules: a list of module name, position in percent and arguments.
396 0%=left/up <-> 100%=right/down.
397 Example: '((clock 1) (label 50 \"My label\") (clickable-clock 90))
398 size: toolbar size in percent of root size
399 thickness: toolbar height for horizontal toolbar or width for vertical one
400 autohide: one of nil, :click, or :motion
401 refresh-delay: refresh delay for toolbar in seconds
402 border-size: toolbar window border size"
403 (let ((toolbar (make-toolbar :root-x root-x :root-y root-y
404 :direction direction :size size
405 :thickness thickness
406 :placement placement
407 :autohide autohide
408 :refresh-delay refresh-delay
409 :border-size border-size
410 :modules (create-toolbar-modules modules))))
411 (push toolbar *toolbar-list*)
412 toolbar))
415 (add-hook *init-hook* 'open-all-toolbars)
416 (add-hook *close-hook* 'close-all-toolbars)
419 (defun set-toolbar-module-rectangle (module x y width height)
420 (unless (toolbar-module-rect module)
421 (setf (toolbar-module-rect module) (make-rectangle)))
422 (setf (rectangle-x (toolbar-module-rect module)) x
423 (rectangle-y (toolbar-module-rect module)) y
424 (rectangle-width (toolbar-module-rect module)) width
425 (rectangle-height (toolbar-module-rect module)) height))
427 (defmacro with-set-toolbar-module-rectangle ((module) &body body)
428 (let ((x (gensym)) (y (gensym)) (width (gensym)) (height (gensym)))
429 `(multiple-value-bind (,x ,y ,width ,height)
430 ,@body
431 (set-toolbar-module-rectangle ,module ,x ,y ,width ,height))))
435 (defmacro define-toolbar-module ((name &rest args) &body body)
436 (let ((symbol-fun (toolbar-symbol-fun name)))
437 `(progn
438 (pushnew ',name *toolbar-module-list*)
439 (defun ,symbol-fun (toolbar module ,@(when args `(&optional ,@args)))
440 ,@body))))
442 (defmacro define-toolbar-module-click ((name &rest args) &body body)
443 (let ((symbol-fun (toolbar-symbol-fun name 'click)))
444 `(progn
445 (pushnew ',name *toolbar-module-list*)
446 (defun ,symbol-fun (toolbar module code state ,@(when args `(&optional ,@args)))
447 ,@body))))
450 (defun list-toolbar-modules (&optional (stream t))
451 "List all toolbar modules"
452 (format stream "Toolbar modules availables:~%")
453 (dolist (module (reverse *toolbar-module-list*))
454 (format stream " Module: ~A~%" module)
455 (when (fboundp (toolbar-symbol-fun module))
456 (format stream " ~A~%" (documentation (toolbar-symbol-fun module) 'function)))
457 (when (fboundp (toolbar-symbol-fun module 'click))
458 (format stream " On click: ~A~%" (documentation (toolbar-symbol-fun module 'click) 'function)))))
461 ;;; Modules definitions
465 ;;; Clock module
467 (define-toolbar-module (clock)
468 "A clock module"
469 (multiple-value-bind (s m h)
470 (get-decoded-time)
471 (declare (ignore s))
472 (toolbar-module-text toolbar module "~2,'0D:~2,'0D" h m)))
475 ;;; Clock module with seconds
477 (define-toolbar-module (clock-second)
478 "A clock module with seconds"
479 (multiple-value-bind (s m h)
480 (get-decoded-time)
481 (toolbar-module-text toolbar module "~2,'0D:~2,'0D:~2,'0D" h m s)))
485 ;;; Label module
487 (define-toolbar-module (label text)
488 "(text) - Display a text in toolbar"
489 (toolbar-module-text toolbar module (or text "Empty")))
492 ;;; Clickable label module
494 (define-toolbar-module (clickable-label text action)
495 "(text action) - Display a clickable text in toolbar"
496 (declare (ignore action))
497 (with-set-toolbar-module-rectangle (module)
498 (toolbar-module-text toolbar module (or text "Empty"))))
500 (define-toolbar-module-click (clickable-label text action)
501 "Call the function 'action'"
502 (declare (ignore text))
503 (when action
504 (funcall action toolbar module code state )))
507 ;;; Clickable clock module
509 (define-toolbar-module (clickable-clock)
510 "A clickable clock module"
511 (multiple-value-bind (s m h)
512 (get-decoded-time)
513 (declare (ignore s))
514 (with-set-toolbar-module-rectangle (module)
515 (toolbar-module-text toolbar module "(~2,'0D:~2,'0D)" h m))))
518 (defconfig *toolbar-clock-action* "xclock -analog"
519 'toolbar "Toolbar clickable clock module action on click")
521 (define-toolbar-module-click (clickable-clock)
522 "Start an external clock"
523 (declare (ignore toolbar module state))
524 (when (= code 1)
525 (do-shell *toolbar-clock-action*)))
528 (format t "done~%")
532 ;;; CLFSWM menu module
534 (define-toolbar-module (clfswm-menu text placement)
535 "(text placement) - Display an entry for the CLFSWM menu"
536 (declare (ignore placement))
537 (with-set-toolbar-module-rectangle (module)
538 (toolbar-module-text toolbar module (or text "(CLFSWM)"))))
540 (define-toolbar-module-click (clfswm-menu text placement)
541 "Open the CLFSWM main menu"
542 (declare (ignore text code state toolbar module))
543 (let ((*info-mode-placement* (or placement *info-mode-placement*)))
544 (open-menu)))
547 ;;; CPU usage
549 (define-toolbar-module (cpu)
550 "Display the CPU usage"
551 (toolbar-module-text toolbar module "CPU:~A%" (cpu-usage)))
555 ;;; Memory usage
557 (define-toolbar-module (mem)
558 "Display the memory usage"
559 (multiple-value-bind (used total)
560 (memory-usage)
561 (toolbar-module-text toolbar module "Mem:~A%" (round (* (/ used total) 100.0)))))
566 ;;; Battery usage
568 (define-toolbar-module (bat)
569 "Display the battery usage"
570 (let* ((bat (battery-usage))
571 (alert (battery-alert-string bat)))
572 (toolbar-module-text toolbar module "Bat:~A~A%~A" alert bat alert)))
577 ;;; System usage - Battery, CPU and Memory usage all in one
579 (define-toolbar-module (system-usage (poll-delay 10))
580 "Display system usage: CPU, Memory and Battery (poll methode)"
581 (multiple-value-bind (cpu used total bat)
582 (system-usage-poll poll-delay)
583 (let ((alert (battery-alert-string bat)))
584 (toolbar-module-text toolbar module "Bat:~A~A%~A CPU:~A% Mem:~A%"
585 alert bat alert cpu
586 (round (* (/ used total) 100))))))
589 ;;; CPU and Memory usage - CPU and Memory usage
591 (define-toolbar-module (system-cpu-mem (poll-delay 10))
592 "Display system usage: CPU and Memory (poll methode)"
593 (multiple-value-bind (cpu used total)
594 (system-usage-poll poll-delay)
595 (toolbar-module-text toolbar module "CPU:~A% Mem:~A%"
597 (round (* (/ used total) 100)))))