[PATCH] exit function



Hi all,

Sawfish 1.6.0 provides reboot/shutdown menu-entries, but if you're not
using KDE/GNOME it just plainly calls shutdown, which has several
disadvantages (else it uses the logout dialog from KDE or GNOME):

a) all windows (better: processes) get signaled 15 or 9
b) possible data loss (mostly window-history file is broken)
c) it's ugly

So I wrote a new function called exit, which is basically a wrapper
around exit, reboot and halt. First it delete-window-safely all windows
(though there should be a customizable list of windows to ignore here,
as that's suboptimal for screenlets for example, but that's not on my
agenda yet, feel free to expand exit if you have some more freetime
than I have), then it window-history-save and THEN it either quits,
reboots or halts.

I think this solution is much better than the previous one.

Regards,
Chris

Patch against HEAD:

diff --git a/lisp/sawfish/wm/autoload.jl b/lisp/sawfish/wm/autoload.jl
index 2f1131a..4e93f93 100644
--- a/lisp/sawfish/wm/autoload.jl
+++ b/lisp/sawfish/wm/autoload.jl
@@ -142,6 +142,7 @@
 (autoload-command 'cycle-dock-backwards 'sawfish.wm.commands.x-cycle)
 (autoload-command 'xterm 'sawfish.wm.commands.user)
 (autoload-command 'browser 'sawfish.wm.commands.user)
+(autoload-command 'exit 'sawfish.wm.commands.user)
 (autoload-command '3d-hack 'sawfish.wm.ext.3d-hack)
 (autoload-command 'rename-window 'sawfish.wm.windows)
 (defgroup audio "Sound" :require sawfish.wm.ext.audio-events)
diff --git a/lisp/sawfish/wm/commands/user.jl
b/lisp/sawfish/wm/commands/user.jl index 0caf38a..e491e79 100644
--- a/lisp/sawfish/wm/commands/user.jl
+++ b/lisp/sawfish/wm/commands/user.jl
@@ -21,7 +21,8 @@
 (define-structure sawfish.wm.commands.user
 
     (export xterm
-	    browser)
+	    browser
+	    exit)
 
     (open rep
 	  rep.system
@@ -30,7 +31,8 @@
 	  rep.io.files
 	  sawfish.wm.misc
 	  sawfish.wm.custom
-	  sawfish.wm.commands)
+	  sawfish.wm.commands
+	  sawfish.wm.windows)
 
   (defgroup apps "Default Applications" :group misc)
 
@@ -60,6 +62,16 @@
       (system (format nil "%s %s >/dev/null 2>&1 </dev/null &"
                       browser-program website))))
 
+  (define (exit action)
+    (require 'sawfish.wm.ext.window-history)
+    (map-windows delete-window-safely)
+    (window-history-save)
+    (case action
+      ((exit) (quit))
+      ((reboot) (system "sudo shutdown -r now &"))
+      ((halt) (system "sudo shutdown -h now &"))))
+
   ;;###autoload
   (define-command 'xterm xterm #:class 'default)
-  (define-command 'browser browser #:class 'default))
+  (define-command 'browser browser #:class 'default)
+  (define-command 'exit exit #:class 'default))
diff --git a/lisp/sawfish/wm/defaults.jl b/lisp/sawfish/wm/defaults.jl
index 02531c4..d1e8a7a 100644
--- a/lisp/sawfish/wm/defaults.jl
+++ b/lisp/sawfish/wm/defaults.jl
@@ -49,9 +49,9 @@
     (when menu
       (nconc menu `(()
                     (,(_ "_Reboot System")
-                     (system "sudo shutdown -r now &"))
+                     (exit 'reboot))
                     (,(_ "_Shutdown System")
-                     (system "sudo shutdown -h now &")))))))))
+                     (exit 'halt)))))))))
 
 ;; save errors to aid debugging
 (require 'sawfish.wm.ext.error-handler)
diff --git a/lisp/sawfish/wm/menus.jl b/lisp/sawfish/wm/menus.jl
index 1d5f63c..4a17f52 100644
--- a/lisp/sawfish/wm/menus.jl
+++ b/lisp/sawfish/wm/menus.jl
@@ -153,7 +153,7 @@ before killing it.")
        (,(_ "Reload Appsmenu") update-apps-menu)
        ()
        (,(_ "Restart Sawfish") restart)
-       (,(_ "Quit Sawfish") quit))
+       (,(_ "Quit Sawfish") (exit 'exit)))
       ()
       (,(_ "_Help")
        (,(_ "_FAQ...") help:show-faq)
diff --git a/man/sawfish.texi b/man/sawfish.texi
index b348407..63e5797 100644
--- a/man/sawfish.texi
+++ b/man/sawfish.texi
@@ -5514,6 +5514,16 @@ Calls the function of the same name.
@code{destroy-window} and @code{kill-client} both take @code{%W} as
argument. @end defun
 
+ defun exit @var{action}
+A wrapper around @code{quit}. @code{exit} first
@code{delete-window-safely} +all managed windows, then
@code{window-history-save}, to ensure a clean +window-history on the
next start. In addition, if @var{action} is @code{exit}, +then
@code{quit} is called directly afterwards, if it's @code{reboot}, then
+the system goes @code{init 6}, if it's halt, then the system goes
@code{init 0}. + +Should not be used, if a session-manager is running.
+ end defun
+
 @node Keymaps, Event Loop, Commands, Top
 @chapter Keymaps
 @cindex Keymaps


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]