1 ;;; --------------------------------------------------------------------------
2 ;;; CLFSWM - FullScreen Window Manager
4 ;;; --------------------------------------------------------------------------
5 ;;; Documentation: Toolbar
6 ;;; --------------------------------------------------------------------------
8 ;;; (C) 2012 Philippe Brochard <pbrochard@common-lisp.net>
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.
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.
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.
24 ;;; Documentation: If you want to use this file, just add this line in
25 ;;; your configuration file:
27 ;;; (load-contrib "toolbar.lisp")
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.
32 ;;; For convenience, here is the add-toolbar documentation:
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"
52 ;;; Here are some examples:
53 ;;; (load-contrib "toolbar.lisp")
55 ;;; ;; Add an horizontal toolbar on root at coordinates 0,0 pixels
56 ;;; ;; with default modules
58 ;;; (add-toolbar 0 0 :horiz 80 'top-middle-root-placement *default-toolbar*)
61 ;;; ;; Add an horizontal toolbar on root at coordinates 0,0 pixels
63 ;;; (add-toolbar 0 0 :horiz 90 'top-middle-root-placement
64 ;;; '((clock 1) (label 50 "Plop") (clock-second 25) (clickable-clock 99))
69 ;;; ;; Add an horizontal toolbar on root at coordinates 0,0 pixels
71 ;;; (add-toolbar 0 0 :horiz 70 'bottom-middle-root-placement '((clock 1) (label 50 "Paf) (clock 99))
72 ;;; :autohide :motion)
75 ;;; ;; Add a vertical toolbar on root 0
77 ;;; (add-toolbar 0 nil :vert 60 'middle-left-root-placement '((clock 1) (label 50 "My label") (clock 90)))
80 ;;; ;; Add a vertical toolbar on root 1
82 ;;; (add-toolbar 1 nil :vert 70 'bottom-right-root-placement '((clock 1) (label 50) (clickable-clock 99)))
83 ;;; --------------------------------------------------------------------------
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)
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
)))))
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 color
)
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
))
161 (xlib:drawable-height
(toolbar-window toolbar
)))))
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
)))
170 (xlib:font-ascent
(toolbar-font toolbar
)))))
171 (loop for c across text
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
))
178 (xlib:with-gcontext
((toolbar-gc toolbar
) :foreground
(get-color color
))
179 (case (toolbar-direction toolbar
)
180 (:horiz
(horiz-text))
181 (:vert
(vert-text))))))
184 (defun toolbar-module-text (toolbar module color formatter
&rest text
)
185 "Print a formatted text at module position centered in toolbar"
186 (toolbar-draw-text toolbar
(toolbar-module-pos module
) (/ *toolbar-default-thickness
* 2)
187 (apply #'format nil formatter text
)
192 (defun refresh-toolbar (toolbar)
193 (unless (toolbar-hide-state toolbar
)
194 (add-timer (toolbar-refresh-delay toolbar
)
196 (refresh-toolbar toolbar
))
198 (clear-pixmap-buffer (toolbar-window toolbar
) (toolbar-gc toolbar
))
199 (dolist (module (toolbar-modules toolbar
))
200 (when (fboundp (toolbar-module-display-fun module
))
201 (apply (toolbar-module-display-fun module
) toolbar module
(toolbar-module-args module
))))
202 (copy-pixmap-buffer (toolbar-window toolbar
) (toolbar-gc toolbar
))))
204 (defun toolbar-in-sensibility-zone-p (toolbar root-x root-y
)
205 (let* ((tb-win (toolbar-window toolbar
))
206 (win-x (xlib:drawable-x tb-win
))
207 (win-y (xlib:drawable-y tb-win
))
208 (width (xlib:drawable-width tb-win
))
209 (height (xlib:drawable-height tb-win
))
210 (tb-dir (toolbar-direction toolbar
) )
211 (placement-name (symbol-name (toolbar-placement toolbar
))))
212 (or (and (equal tb-dir
:horiz
) (search "TOP" placement-name
)
213 (<= root-y win-y
(+ root-y
*toolbar-sensibility
*))
214 (<= win-x root-x
(+ win-x width
)) (toolbar-autohide toolbar
))
215 (and (equal tb-dir
:horiz
) (search "BOTTOM" placement-name
)
216 (<= (+ win-y height
(- *toolbar-sensibility
*)) root-y
(+ win-y height
))
217 (<= win-x root-x
(+ win-x width
)) (toolbar-autohide toolbar
))
218 (and (equal tb-dir
:vert
) (search "LEFT" placement-name
)
219 (<= root-x win-x
(+ root-x
*toolbar-sensibility
*))
220 (<= win-y root-y
(+ win-y height
)) (toolbar-autohide toolbar
))
221 (and (equal tb-dir
:vert
) (search "RIGHT" placement-name
)
222 (<= (+ win-x width
(- *toolbar-sensibility
*)) root-x
(+ win-x width
))
223 (<= win-y root-y
(+ win-y height
)) (toolbar-autohide toolbar
)))))
225 (use-event-hook :exposure
)
226 (use-event-hook :button-press
)
227 (use-event-hook :motion-notify
)
228 (use-event-hook :leave-notify
)
231 (defun toolbar-add-exposure-hook (toolbar)
232 (define-event-hook :exposure
(window)
233 (when (and (xlib:window-p window
) (xlib:window-equal
(toolbar-window toolbar
) window
))
234 (refresh-toolbar toolbar
))))
236 (defun toolbar-add-hide-button-press-hook (toolbar)
237 (define-event-hook :button-press
(code root-x root-y
)
239 (let* ((tb-win (toolbar-window toolbar
)))
240 (when (toolbar-in-sensibility-zone-p toolbar root-x root-y
)
241 (if (toolbar-hide-state toolbar
)
243 (setf (toolbar-hide-state toolbar
) nil
)
245 (raise-window tb-win
)
246 (refresh-toolbar toolbar
))
249 (setf (toolbar-hide-state toolbar
) t
)))
250 (wait-mouse-button-release)
252 (exit-handle-event))))))
254 (defun toolbar-add-hide-motion-hook (toolbar)
255 (define-event-hook :motion-notify
(root-x root-y
)
256 (unless (compress-motion-notify)
257 (when (and (toolbar-hide-state toolbar
)
258 (toolbar-in-sensibility-zone-p toolbar root-x root-y
))
259 (map-window (toolbar-window toolbar
))
260 (raise-window (toolbar-window toolbar
))
261 (refresh-toolbar toolbar
)
262 (setf (toolbar-hide-state toolbar
) nil
)
263 (exit-handle-event)))))
265 (defun toolbar-add-hide-leave-hook (toolbar)
266 (define-event-hook :leave-notify
(root-x root-y
)
267 (when (and (not (toolbar-hide-state toolbar
))
268 (not (in-window (toolbar-window toolbar
) root-x root-y
)))
269 (hide-window (toolbar-window toolbar
))
270 (setf (toolbar-hide-state toolbar
) t
)
271 (exit-handle-event))))
274 (defun toolbar-add-clickable-module-hook (toolbar)
275 (define-event-hook :button-press
(code state root-x root-y
)
276 (when (and (in-window (toolbar-window toolbar
) root-x root-y
)
277 (not (toolbar-hide-state toolbar
)))
278 (dolist (module (toolbar-modules toolbar
))
279 (when (and (in-rectangle root-x root-y
(toolbar-module-rect module
))
280 (fboundp (toolbar-module-click-fun module
)))
281 (apply (toolbar-module-click-fun module
) toolbar module code state
282 (toolbar-module-args module
))
284 (exit-handle-event))))))
287 (defun define-toolbar-hooks (toolbar)
288 (toolbar-add-exposure-hook toolbar
)
289 (when (toolbar-clickable toolbar
)
290 (toolbar-add-clickable-module-hook toolbar
))
291 (case (toolbar-autohide toolbar
)
292 (:click
(toolbar-add-hide-button-press-hook toolbar
))
293 (:motion
(toolbar-add-hide-motion-hook toolbar
)
294 (toolbar-add-hide-leave-hook toolbar
))))
296 (defun set-clickable-toolbar (toolbar)
297 (dolist (module (toolbar-modules toolbar
))
298 (when (fboundp (toolbar-module-click-fun module
))
299 (setf (toolbar-clickable toolbar
) t
))))
303 (let ((windows-list nil
))
304 (defun is-toolbar-window-p (win)
305 (and (xlib:window-p win
) (member win windows-list
:test
'xlib
:window-equal
)))
307 (defun close-toolbar (toolbar)
308 (erase-timer :refresh-toolbar-window
)
309 (setf *never-managed-window-list
*
310 (remove (list #'is-toolbar-window-p nil
)
311 *never-managed-window-list
* :test
#'equal
))
312 (awhen (toolbar-gc toolbar
)
313 (xlib:free-gcontext it
))
314 (awhen (toolbar-window toolbar
)
315 (xlib:destroy-window it
))
316 (awhen (toolbar-font toolbar
)
317 (xlib:close-font it
))
318 (xlib:display-finish-output
*display
*)
319 (setf (toolbar-window toolbar
) nil
320 (toolbar-gc toolbar
) nil
321 (toolbar-font toolbar
) nil
))
323 (defun open-toolbar (toolbar)
324 (let ((root (root (toolbar-root-x toolbar
) (toolbar-root-y toolbar
))))
326 (setf (toolbar-root toolbar
) root
)
327 (let ((*get-current-root-fun
* (lambda () root
)))
328 (setf (toolbar-font toolbar
) (xlib:open-font
*display
* *toolbar-window-font-string
*))
329 (let* ((width (if (equal (toolbar-direction toolbar
) :horiz
)
330 (round (/ (* (root-w root
) (toolbar-size toolbar
)) 100))
331 (toolbar-thickness toolbar
)))
332 (height (if (equal (toolbar-direction toolbar
) :horiz
)
333 (toolbar-thickness toolbar
)
334 (round (/ (* (root-h root
) (toolbar-size toolbar
)) 100)))))
335 (with-placement ((toolbar-placement toolbar
) x y width height
(toolbar-border-size toolbar
))
336 (setf (toolbar-window toolbar
) (xlib:create-window
:parent
*root
*
341 :background
(get-color *toolbar-window-background
*)
342 :border-width
(toolbar-border-size toolbar
)
343 :border
(when (plusp (toolbar-border-size toolbar
))
344 (get-color *toolbar-window-border
*))
345 :colormap
(xlib:screen-default-colormap
*screen
*)
346 :event-mask
'(:exposure
:key-press
:leave-window
348 (toolbar-gc toolbar
) (xlib:create-gcontext
:drawable
(toolbar-window toolbar
)
349 :foreground
(get-color *toolbar-window-foreground
*)
350 :background
(get-color *toolbar-window-background
*)
351 :font
(toolbar-font toolbar
)
353 (push (toolbar-window toolbar
) windows-list
)
354 (setf (window-transparency (toolbar-window toolbar
)) *toolbar-window-transparency
*)
355 (push (list #'is-toolbar-window-p nil
) *never-managed-window-list
*)
356 (map-window (toolbar-window toolbar
))
357 (raise-window (toolbar-window toolbar
))
358 (refresh-toolbar toolbar
)
359 (when (toolbar-autohide toolbar
)
360 (hide-window (toolbar-window toolbar
))
361 (setf (toolbar-hide-state toolbar
) t
))
362 (xlib:display-finish-output
*display
*)
363 (set-clickable-toolbar toolbar
)
364 (define-toolbar-hooks toolbar
))))))))
367 (defun open-all-toolbars ()
369 (dolist (toolbar *toolbar-list
*)
370 (open-toolbar toolbar
))
371 (dolist (toolbar *toolbar-list
*)
372 (toolbar-adjust-root-size toolbar
)))
374 (defun close-all-toolbars ()
375 (dolist (toolbar *toolbar-list
*)
376 (close-toolbar toolbar
))
379 (defun create-toolbar-modules (modules)
380 (loop for mod in modules
381 collect
(make-toolbar-module :name
(first mod
)
383 :display-fun
(toolbar-symbol-fun (first mod
))
384 :click-fun
(toolbar-symbol-fun (first mod
) 'click
)
389 (defun add-toolbar (root-x root-y direction size placement modules
390 &key
(autohide *toolbar-default-autohide
*)
391 (thickness *toolbar-default-thickness
*)
392 (refresh-delay *toolbar-default-refresh-delay
*)
393 (border-size *toolbar-default-border-size
*))
395 root-x, root-y: root coordinates or if root-y is nil, root-x is the nth root in root-list.
396 direction: one of :horiz or :vert
397 placement: same argument as with-placement macro
398 modules: list of modules: a list of module name, position in percent and arguments.
399 0%=left/up <-> 100%=right/down.
400 Example: '((clock 1) (label 50 \"My label\") (clickable-clock 90))
401 size: toolbar size in percent of root size
402 thickness: toolbar height for horizontal toolbar or width for vertical one
403 autohide: one of nil, :click, or :motion
404 refresh-delay: refresh delay for toolbar in seconds
405 border-size: toolbar window border size"
406 (let ((toolbar (make-toolbar :root-x root-x
:root-y root-y
407 :direction direction
:size size
411 :refresh-delay refresh-delay
412 :border-size border-size
413 :modules
(create-toolbar-modules modules
))))
414 (push toolbar
*toolbar-list
*)
418 (add-hook *init-hook
* 'open-all-toolbars
)
419 (add-hook *close-hook
* 'close-all-toolbars
)
422 (defun set-toolbar-module-rectangle (module x y width height
)
423 (unless (toolbar-module-rect module
)
424 (setf (toolbar-module-rect module
) (make-rectangle)))
425 (setf (rectangle-x (toolbar-module-rect module
)) x
426 (rectangle-y (toolbar-module-rect module
)) y
427 (rectangle-width (toolbar-module-rect module
)) width
428 (rectangle-height (toolbar-module-rect module
)) height
))
430 (defmacro with-set-toolbar-module-rectangle
((module) &body body
)
431 (let ((x (gensym)) (y (gensym)) (width (gensym)) (height (gensym)))
432 `(multiple-value-bind (,x
,y
,width
,height
)
434 (set-toolbar-module-rectangle ,module
,x
,y
,width
,height
))))
438 (defmacro define-toolbar-module
((name &rest args
) &body body
)
439 (let ((symbol-fun (toolbar-symbol-fun name
)))
441 (pushnew ',name
*toolbar-module-list
*)
442 (defun ,symbol-fun
(toolbar module
,@(when args
`(&optional
,@args
)))
445 (defmacro define-toolbar-module-click
((name &rest args
) &body body
)
446 (let ((symbol-fun (toolbar-symbol-fun name
'click
)))
448 (pushnew ',name
*toolbar-module-list
*)
449 (defun ,symbol-fun
(toolbar module code state
,@(when args
`(&optional
,@args
)))
453 (defun list-toolbar-modules (&optional
(stream t
))
454 "List all toolbar modules"
455 (format stream
"Toolbar modules availables:~%")
456 (dolist (module (reverse *toolbar-module-list
*))
457 (format stream
" Module: ~A~%" module
)
458 (when (fboundp (toolbar-symbol-fun module
))
459 (format stream
" ~A~%" (documentation (toolbar-symbol-fun module
) 'function
)))
460 (when (fboundp (toolbar-symbol-fun module
'click
))
461 (format stream
" On click: ~A~%" (documentation (toolbar-symbol-fun module
'click
) 'function
)))))
464 (defmacro define-toolbar-color
(name doc-string
&optional
(value *toolbar-window-foreground
*))
465 (let ((symbol-name (create-symbol '*toolbar- name
'-color
*)))
466 `(defconfig ,symbol-name
,value
'Toolbar
,doc-string
)))
468 (defmacro tb-color
(name)
469 (let ((symbol-name (create-symbol '*toolbar- name
'-color
*)))
473 ;;; Modules definitions
479 (define-toolbar-color clock
"Clock color")
481 (define-toolbar-module (clock)
483 (multiple-value-bind (s m h
)
486 (toolbar-module-text toolbar module
(tb-color clock
) "~2,'0D:~2,'0D" h m
)))
489 ;;; Clock module with seconds
491 (define-toolbar-module (clock-second)
492 "A clock module with seconds"
493 (multiple-value-bind (s m h
)
495 (toolbar-module-text toolbar module
(tb-color clock
) "~2,'0D:~2,'0D:~2,'0D" h m s
)))
501 (define-toolbar-color label
"Label color")
503 (define-toolbar-module (label text
)
504 "(text) - Display a text in toolbar"
505 (toolbar-module-text toolbar module
(tb-color label
) (or text
"Empty")))
508 ;;; Clickable label module
510 (define-toolbar-color clickable-label
"Clickable label color")
512 (define-toolbar-module (clickable-label text action
)
513 "(text action) - Display a clickable text in toolbar"
514 (declare (ignore action
))
515 (with-set-toolbar-module-rectangle (module)
516 (toolbar-module-text toolbar module
(tb-color clickable-label
) (or text
"Empty"))))
518 (define-toolbar-module-click (clickable-label text action
)
519 "Call the function 'action'"
520 (declare (ignore text
))
522 (funcall action toolbar module code state
)))
525 ;;; Clickable clock module
527 (define-toolbar-color clickable-clock
"Clickable clock color")
529 (define-toolbar-module (clickable-clock)
530 "A clickable clock module"
531 (multiple-value-bind (s m h
)
534 (with-set-toolbar-module-rectangle (module)
535 (toolbar-module-text toolbar module
(tb-color clickable-clock
) "~2,'0D:~2,'0D" h m
))))
538 (defconfig *toolbar-clock-action
* "xclock -analog"
539 'toolbar
"Toolbar clickable clock module action on click")
541 (define-toolbar-module-click (clickable-clock)
542 "Start an external clock"
543 (declare (ignore toolbar module state
))
545 (do-shell *toolbar-clock-action
*)))
552 ;;; CLFSWM menu module
554 (define-toolbar-color clfswm-menu
"CLFSWM menu color")
556 (define-toolbar-module (clfswm-menu text placement
)
557 "(text placement) - Display an entry for the CLFSWM menu"
558 (declare (ignore placement
))
559 (with-set-toolbar-module-rectangle (module)
560 (toolbar-module-text toolbar module
(tb-color clfswm-menu
) (or text
"CLFSWM"))))
562 (define-toolbar-module-click (clfswm-menu text placement
)
563 "Open the CLFSWM main menu"
564 (declare (ignore text code state toolbar module
))
565 (let ((*info-mode-placement
* (or placement
*info-mode-placement
*)))
571 (define-toolbar-color cpu
"CPU color")
573 (define-toolbar-module (cpu)
574 "Display the CPU usage (slow methode)"
575 (toolbar-module-text toolbar module
(tb-color cpu
) "CPU:~A%" (cpu-usage)))
581 (define-toolbar-color mem
"Memory color")
583 (define-toolbar-module (mem)
584 "Display the memory usage (slow methode)"
585 (multiple-value-bind (used total
)
587 (toolbar-module-text toolbar module
(tb-color mem
) "Mem:~A%" (round (* (/ used total
) 100.0)))))
594 (define-toolbar-color system-info
"System information colors (CPU+Mem+Battery)")
595 (define-toolbar-color system-info-low
"System information colors (CPU+Mem+Battery)" "Yellow")
596 (define-toolbar-color system-info-alert
"System information colors (CPU+Mem+Battery)" "Magenta")
597 (define-toolbar-color system-info-urgent
"System information colors (CPU+Mem+Battery)" "Red")
599 (defun toolbar-battery-color (bat)
601 (cond ((<= bat
5) (tb-color system-info-urgent
))
602 ((<= bat
10) (tb-color system-info-alert
))
603 ((<= bat
25) (tb-color system-info-low
))
604 (t (tb-color system-info
)))
605 (tb-color system-info
)))
607 (define-toolbar-module (bat)
608 "Display the battery usage (slow methode)"
609 (let* ((bat (battery-usage)))
610 (toolbar-module-text toolbar module
611 (toolbar-battery-color bat
)
617 ;;; System usage - Battery, CPU and Memory usage all in one
619 (define-toolbar-module (system-usage (poll-delay 10))
620 "Display system usage: CPU, Memory and Battery (poll methode)"
621 (multiple-value-bind (cpu used total bat
)
622 (system-usage-poll poll-delay
)
623 (toolbar-module-text toolbar module
(toolbar-battery-color bat
)
624 "Bat:~A% CPU:~A% Mem:~A%"
626 (round (* (/ used total
) 100)))))
629 ;;; CPU and Memory usage - CPU and Memory usage
631 (define-toolbar-module (system-cpu-mem (poll-delay 10))
632 "Display system usage: CPU and Memory (poll methode)"
633 (multiple-value-bind (cpu used total
)
634 (system-usage-poll poll-delay
)
635 (toolbar-module-text toolbar module
(tb-color cpu
)
638 (round (* (/ used total
) 100)))))