Fixe unmap-notify request
[clfswm.git] / contrib / reboot-halt.lisp
blob455f19a84f6659442d56b477c4d9699b49570701
1 ;;; --------------------------------------------------------------------------
2 ;;; CLFSWM - FullScreen Window Manager
3 ;;;
4 ;;; --------------------------------------------------------------------------
5 ;;; Documentation: Reboot and halt menu
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 "mpd.lisp")
28 ;;;
29 ;;; --------------------------------------------------------------------------
31 (in-package :clfswm)
33 (format t "Loading Reboot/Halt code... ")
35 (defconfig *power-suspend-to-ram-cmd* "sudo pm-suspend"
36 'power-management "Suspend to ram command")
37 (defconfig *power-suspend-to-disk-cmd* "sudo pm-hibernate"
38 'power-management "Suspend to disk command")
39 (defconfig *power-reboot-cmd* "sudo /sbin/reboot"
40 'power-management "Reboot command")
41 (defconfig *power-halt-cmd* "sudo /sbin/halt"
42 'power-management "Halt command")
44 (defun reboot-halt-menu ()
45 "Open the Reboot/Halt menu"
46 (open-menu (find-menu 'reboot-halt-menu)))
49 (defun do-with-terminal (command)
50 (do-shell (format nil "xterm -e '~A'" command)))
51 ;;(do-shell (format nil "xterm -e 'echo ~A; sleep 3'" command))) ;; test
53 (defun do-nothing ()
54 "Do nothing"
55 ())
57 (defun do-suspend ()
58 "Suspend the computer to RAM"
59 (do-with-terminal *power-suspend-to-ram-cmd*))
61 (defun do-hibernate ()
62 "Suspend the computer to DISK"
63 (do-with-terminal *power-suspend-to-disk-cmd*))
65 (defun do-reboot ()
66 "Reboot the computer"
67 (do-with-terminal *power-reboot-cmd*))
69 (defun do-halt ()
70 "Halt the computer"
71 (do-with-terminal *power-halt-cmd*))
73 (unless (find-menu 'reboot-halt-menu)
74 (add-sub-menu 'clfswm-menu "Pause" 'reboot-halt-menu "Suspend/Reboot/Halt menu")
75 (add-menu-key 'reboot-halt-menu "-" 'do-nothing)
76 (add-menu-key 'reboot-halt-menu "s" 'do-suspend)
77 (add-menu-key 'reboot-halt-menu "d" 'do-hibernate)
78 (add-menu-key 'reboot-halt-menu "r" 'do-reboot)
79 (add-menu-key 'reboot-halt-menu "h" 'do-halt))
82 (defun reboot-halt-binding ()
83 (define-main-key ("Pause") 'reboot-halt-menu))
85 (add-hook *binding-hook* 'reboot-halt-binding)
87 (format t "done~%")