diff -u'rNF^function' xfce4-session-4.3.90.2svn-r22296.orig/config.h.in xfce4-session-4.3.90.2svn-r22296/config.h.in --- xfce4-session-4.3.90.2svn-r22296.orig/config.h.in 2006-07-08 19:37:31.000000000 +0200 +++ xfce4-session-4.3.90.2svn-r22296/config.h.in 2006-07-18 15:13:10.000000000 +0200 @@ -168,6 +168,12 @@ /* Shutdown helper implementation */ #undef XFSM_SHUTDOWN_HELPER_IMPL_C +/* Hibernate command */ +#undef HIBERNATE_CMD + +/* Suspend command */ +#undef SUSPEND_CMD + /* Define to 1 if the X Window System is missing or not being used. */ #undef X_DISPLAY_MISSING diff -u'rNF^function' xfce4-session-4.3.90.2svn-r22296.orig/configure.in xfce4-session-4.3.90.2svn-r22296/configure.in --- xfce4-session-4.3.90.2svn-r22296.orig/configure.in 2006-07-08 19:36:58.000000000 +0200 +++ xfce4-session-4.3.90.2svn-r22296/configure.in 2006-07-19 19:42:43.000000000 +0200 @@ -71,6 +71,8 @@ XDT_CHECK_PACKAGE([LIBXFCE4UTIL], [libxfce4util-1.0], [4.3.90.2]) XDT_CHECK_PACKAGE([LIBXFCE4MCS_CLIENT], [libxfce4mcs-client-1.0], [4.3.90.1]) XDT_CHECK_PACKAGE([LIBXFCEGUI4], [libxfcegui4-1.0], [4.3.90.2]) +XDT_CHECK_PACKAGE([DBUS], [dbus-glib-1], [0.34]) +XDT_CHECK_PACKAGE([HAL], [hal], [0.5.5]) dnl Configure the MCS plugins XDT_XFCE_MCS_PLUGIN([XFCE_MCS_MANAGER], [4.3.90.2]) @@ -134,9 +136,26 @@ [Shutdown helper implementation]) AC_MSG_RESULT([$with_shutdown]) -dnl -dnl arguments to set shutdown commands -dnl +dnl extending search path for AC_PATH_PROG +XPATH=$prefix/share/hal/scripts:$DESTDIR$prefix/share/hal/scripts:$PATH + +dnl Check for hibernate command +AC_PATH_PROG(HIBERNATE_CMD_STD, hal-system-power-hibernate,,$XPATH) +AC_ARG_WITH([hibernate-command], + AC_HELP_STRING([--with-hibernate-command=cmd], [command used to hibernate system (full path with arguments)]), + [with_hibernate=$withval], [with_hibernate=$HIBERNATE_CMD_STD]) +AC_MSG_CHECKING([for 'hibernate' command]) +AC_DEFINE_UNQUOTED([HIBERNATE_CMD], "$with_hibernate", [hibernate command]) +AC_MSG_RESULT([$with_hibernate]) + +dnl Check for suspend command +AC_PATH_PROG(SUSPEND_CMD_STD, hal-system-power-suspend,,$XPATH) +AC_ARG_WITH([suspend-command], + AC_HELP_STRING([--with-suspend-command=cmd], [command used to suspend system (full path with arguments)]), + [with_suspend=$withval], [with_suspend=$SUSPEND_CMD_STD]) +AC_MSG_CHECKING([for 'suspend' command]) +AC_DEFINE_UNQUOTED([SUSPEND_CMD], "$with_suspend", [suspend command]) +AC_MSG_RESULT([$with_suspend]) dnl AC_MSG_CHECKING([for custom 'poweroff' command]) dnl AC_ARG_WITH([poweroff], diff -u'rNF^function' xfce4-session-4.3.90.2svn-r22296.orig/icons/48x48/Makefile.in xfce4-session-4.3.90.2svn-r22296/icons/48x48/Makefile.in --- xfce4-session-4.3.90.2svn-r22296.orig/icons/48x48/Makefile.in 2006-07-08 19:37:11.000000000 +0200 +++ xfce4-session-4.3.90.2svn-r22296/icons/48x48/Makefile.in 2006-07-29 13:48:50.000000000 +0200 @@ -248,6 +248,8 @@ xfce4-splash.png \ xfsm-logout.png \ xfsm-reboot.png \ + xfsm-suspend.png \ + xfsm-hibernate.png \ xfsm-shutdown.png EXTRA_DIST = $(icons_DATA) Files xfce4-session-4.3.90.2svn-r22296.orig/icons/48x48/xfsm-hibernate.png and xfce4-session-4.3.90.2svn-r22296/icons/48x48/xfsm-hibernate.png differ Files xfce4-session-4.3.90.2svn-r22296.orig/icons/48x48/xfsm-suspend.png and xfce4-session-4.3.90.2svn-r22296/icons/48x48/xfsm-suspend.png differ diff -u'rNF^function' xfce4-session-4.3.90.2svn-r22296.orig/settings/session/Makefile.in xfce4-session-4.3.90.2svn-r22296/settings/session/Makefile.in --- xfce4-session-4.3.90.2svn-r22296.orig/settings/session/Makefile.in 2006-07-08 19:37:12.000000000 +0200 +++ xfce4-session-4.3.90.2svn-r22296/settings/session/Makefile.in 2006-07-19 19:44:23.000000000 +0200 @@ -101,6 +101,8 @@ CXXFLAGS = @CXXFLAGS@ CYGPATH_W = @CYGPATH_W@ DATADIRNAME = @DATADIRNAME@ +DBUS_CFLAGS = @DBUS_CFLAGS@ +DBUS_LIBS = @DBUS_LIBS@ DEFS = @DEFS@ DEPDIR = @DEPDIR@ ECHO = @ECHO@ @@ -119,6 +121,8 @@ GNOME_REQUIRED_VERSION = @GNOME_REQUIRED_VERSION@ GNOME_VERSION = @GNOME_VERSION@ GREP = @GREP@ +HAL_CFLAGS = @HAL_CFLAGS@ +HAL_LIBS = @HAL_LIBS@ HAVE_GNOME_FALSE = @HAVE_GNOME_FALSE@ HAVE_GNOME_TRUE = @HAVE_GNOME_TRUE@ HAVE_OS_CYGWIN_FALSE = @HAVE_OS_CYGWIN_FALSE@ @@ -268,12 +272,12 @@ session_LTLIBRARIES = \ session_settings.la -session_settings_la_LDFLAGS = -avoid-version -no-undefined -module \ +session_settings_la_LDFLAGS = @HAL_LIBS@ -avoid-version -no-undefined -module \ $(am__append_1) session_settings_la_SOURCES = \ session.c -session_settings_la_CFLAGS = \ +session_settings_la_CFLAGS = @HAL_CFLAGS@ \ -I$(top_srcdir) \ @XFCE_MCS_MANAGER_CFLAGS@ \ -DPACKAGE_LOCALE_DIR=\"$(localedir)\" diff -u'rNF^function' xfce4-session-4.3.90.2svn-r22296.orig/settings/session/session.c xfce4-session-4.3.90.2svn-r22296/settings/session/session.c --- xfce4-session-4.3.90.2svn-r22296.orig/settings/session/session.c 2006-07-07 23:48:32.000000000 +0200 +++ xfce4-session-4.3.90.2svn-r22296/settings/session/session.c 2006-07-29 13:51:18.000000000 +0200 @@ -19,6 +19,14 @@ * 02111-1307, USA. */ +/* TODO: + * + * - maybe add something like libhal_ctx_shutdown or libhal_ctx_free(hal_ctx) + * in case anything went wrong with dbus and/or hal (lshal doesn't care either) + * + */ + + #ifdef HAVE_CONFIG_H #include #endif @@ -40,6 +48,7 @@ #include #include +#include #define BORDER 6 @@ -51,6 +60,8 @@ static GtkWidget *general_chooser; static GtkWidget *general_autosave; static GtkWidget *general_prompt; +static GtkWidget *general_hibernate; +static GtkWidget *general_suspend; static GtkWidget *advanced_kde; static GtkWidget *advanced_gnome; static GtkWidget *advanced_remote; @@ -88,6 +99,8 @@ { xfce_rc_write_bool_entry (rc, "AutoSave", gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (general_autosave))); xfce_rc_write_bool_entry (rc, "PromptOnLogout", gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (general_prompt))); + xfce_rc_write_bool_entry (rc, "Hibernate", gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (general_hibernate))); + xfce_rc_write_bool_entry (rc, "Suspend", gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (general_suspend))); } if (G_LIKELY (kiosk_can_security)) { @@ -124,10 +137,23 @@ gboolean autosave; gboolean prompt; gboolean chooser; + gboolean hibernate; + gboolean suspend; + dbus_bool_t can_hibernate = FALSE; + dbus_bool_t can_suspend = FALSE; + static char *uid = "/org/freedesktop/Hal/devices/computer"; + static char *hibernate_key_table[] = { "power_management.can_hibernate", "power_management.can_suspend_to_disk" }; + static char *suspend_key_table[] = { "power_management.can_suspend", "power_management.can_suspend_to_ram" }; + DBusError dbusError; + DBusConnection *dbusConnection = NULL; + LibHalContext *hal_ctx = NULL; + xfce_rc_set_group (rc, "General"); autosave = xfce_rc_read_bool_entry (rc, "AutoSave", FALSE); prompt = xfce_rc_read_bool_entry (rc, "PromptOnLogout", TRUE); + hibernate = xfce_rc_read_bool_entry (rc, "Hibernate", FALSE); + suspend = xfce_rc_read_bool_entry (rc, "Suspend", FALSE); xfce_rc_set_group (rc, "Chooser"); chooser = xfce_rc_read_bool_entry (rc, "AlwaysDisplay", FALSE); @@ -182,6 +208,70 @@ "saving of sessions on logout or not."), NULL); + /* support for hibernation */ + general_hibernate = gtk_check_button_new_with_label (_("Show Hibernate")); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (general_hibernate), hibernate); + g_signal_connect (G_OBJECT (general_hibernate), "toggled", + G_CALLBACK (config_store), NULL); + gtk_box_pack_start (GTK_BOX (vbox), general_hibernate, FALSE, TRUE, 0); + gtk_tooltips_set_tip (tooltips, general_hibernate, + _("Enable this option in order to be able to " + "choose Hibernate at logout."), + NULL); + + general_suspend = gtk_check_button_new_with_label (_("Show Suspend")); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (general_suspend), suspend); + g_signal_connect (G_OBJECT (general_suspend), "toggled", + G_CALLBACK (config_store), NULL); + gtk_box_pack_start (GTK_BOX (vbox), general_suspend, FALSE, TRUE, 0); + gtk_tooltips_set_tip (tooltips, general_suspend, + _("Enable this option in order to be able to " + "choose Suspend at logout."), + NULL); + + /* check for hibernation support in kernel */ + dbus_error_init(&dbusError); + if ((dbusConnection = dbus_bus_get(DBUS_BUS_SYSTEM, &dbusError)) == NULL) /* connecting to dbus */ + { + g_warning("error: dbus_bus_get: %s: %s\n", dbusError.name, dbusError.message); + goto hal_error_handle; + } + if ((hal_ctx = libhal_ctx_new()) == NULL) /* allocating context */ + { + g_warning("error: libhal_ctx_new()\n"); + + goto hal_error_handle; + } + if (!libhal_ctx_set_dbus_connection(hal_ctx, dbusConnection)) /* setting up dbus connection */ + { + g_warning("error: libhal_ctx_set_dbus_connection()"); + goto hal_error_handle; + } + if (!libhal_ctx_init(hal_ctx, &dbusError)) /* init hal context */ + { + g_warning("error: libhal_ctx_init(): %s: %s\n", dbusError.name, dbusError.message); + g_warning("Normally this mean the HAL daemon (hald) is not running or not ready.\n"); + goto hal_error_handle; + } + + can_hibernate = libhal_device_get_property_bool (hal_ctx, uid, hibernate_key_table[0], &dbusError); /* check for new key */ + if (!can_hibernate) + can_hibernate = libhal_device_get_property_bool (hal_ctx, uid, hibernate_key_table[1], &dbusError); /* check for depreciated key */ + + can_suspend = libhal_device_get_property_bool (hal_ctx, uid, suspend_key_table[0], &dbusError); + if (!can_suspend) + can_suspend = libhal_device_get_property_bool (hal_ctx, uid, suspend_key_table[1], &dbusError); + + libhal_ctx_shutdown(hal_ctx, &dbusError); + libhal_ctx_free(hal_ctx); + dbus_connection_close(dbusConnection); + dbus_connection_unref (dbusConnection); + +hal_error_handle: + dbus_error_free (&dbusError); + gtk_widget_set_sensitive (general_hibernate, (gboolean)can_hibernate); + gtk_widget_set_sensitive (general_suspend, (gboolean)can_suspend); + return page; } diff -u'rNF^function' xfce4-session-4.3.90.2svn-r22296.orig/xfce4-session/shutdown.c xfce4-session-4.3.90.2svn-r22296/xfce4-session/shutdown.c --- xfce4-session-4.3.90.2svn-r22296.orig/xfce4-session/shutdown.c 2006-07-07 23:48:32.000000000 +0200 +++ xfce4-session-4.3.90.2svn-r22296/xfce4-session/shutdown.c 2006-07-29 13:54:33.000000000 +0200 @@ -134,6 +134,23 @@ gtk_dialog_response (GTK_DIALOG (shutdown_dialog), GTK_RESPONSE_OK); } +static void +hibernate_button_clicked (GtkWidget *b, gint *shutdownType) +{ + *shutdownType = SHUTDOWN_HIBERNATE; + + gtk_dialog_response (GTK_DIALOG (shutdown_dialog), GTK_RESPONSE_OK); +} + +static void +suspend_button_clicked (GtkWidget *b, gint *shutdownType) +{ + *shutdownType = SHUTDOWN_SUSPEND; + + gtk_dialog_response (GTK_DIALOG (shutdown_dialog), GTK_RESPONSE_OK); +} + + /* */ gboolean @@ -156,6 +173,8 @@ GtkWidget *logout_button; GtkWidget *reboot_button; GtkWidget *halt_button; + GtkWidget *hibernate_button; + GtkWidget *suspend_button; GtkWidget *cancel_button; GtkWidget *ok_button; GtkWidget *header; @@ -163,6 +182,8 @@ gboolean saveonexit; gboolean autosave; gboolean prompt; + gboolean hibernate = FALSE; + gboolean suspend = FALSE; gint monitor; gint result; XfceKiosk *kiosk; @@ -196,6 +217,8 @@ saveonexit = xfce_rc_read_bool_entry (rc, "SaveOnExit", TRUE); autosave = xfce_rc_read_bool_entry (rc, "AutoSave", FALSE); prompt = xfce_rc_read_bool_entry (rc, "PromptOnLogout", TRUE); + hibernate = xfce_rc_read_bool_entry (rc, "Hibernate", FALSE); + suspend = xfce_rc_read_bool_entry (rc, "Suspend", FALSE); /* if PromptOnLogout is off, saving depends on AutoSave */ if (!prompt) @@ -341,7 +364,55 @@ label = gtk_label_new (_("Log Out")); gtk_widget_show (label); gtk_box_pack_start (GTK_BOX (vbox2), label, FALSE, FALSE, 0); + + /* hibernate */ + hibernate_button = gtk_button_new (); + gtk_box_pack_start (GTK_BOX (hbox), hibernate_button, TRUE, TRUE, 0); + + g_signal_connect (hibernate_button, "clicked", + G_CALLBACK (hibernate_button_clicked), shutdownType); + + vbox2 = gtk_vbox_new (FALSE, BORDER); + gtk_container_set_border_width (GTK_CONTAINER (vbox2), BORDER); + gtk_widget_show (vbox2); + gtk_container_add (GTK_CONTAINER (hibernate_button), vbox2); + + icon = xfce_themed_icon_load ("xfsm-hibernate", 32); + image = gtk_image_new_from_pixbuf (icon); + gtk_widget_show (image); + gtk_box_pack_start (GTK_BOX (vbox2), image, FALSE, FALSE, 0); + g_object_unref (icon); + label = gtk_label_new (_("Hibernate")); + gtk_widget_show (label); + gtk_box_pack_start (GTK_BOX (vbox2), label, FALSE, FALSE, 0); + + if (hibernate) gtk_widget_show (hibernate_button); + + /* suspend */ + suspend_button = gtk_button_new (); + gtk_box_pack_start (GTK_BOX (hbox), suspend_button, TRUE, TRUE, 0); + + g_signal_connect (suspend_button, "clicked", + G_CALLBACK (suspend_button_clicked), shutdownType); + + vbox2 = gtk_vbox_new (FALSE, BORDER); + gtk_container_set_border_width (GTK_CONTAINER (vbox2), BORDER); + gtk_widget_show (vbox2); + gtk_container_add (GTK_CONTAINER (suspend_button), vbox2); + + icon = xfce_themed_icon_load ("xfsm-suspend", 32); + image = gtk_image_new_from_pixbuf (icon); + gtk_widget_show (image); + gtk_box_pack_start (GTK_BOX (vbox2), image, FALSE, FALSE, 0); + g_object_unref (icon); + + label = gtk_label_new (_("Suspend")); + gtk_widget_show (label); + gtk_box_pack_start (GTK_BOX (vbox2), label, FALSE, FALSE, 0); + + if (suspend) gtk_widget_show (suspend_button); + /* reboot */ reboot_button = gtk_button_new (); gtk_widget_show (reboot_button); @@ -387,7 +458,7 @@ label = gtk_label_new (_("Shut Down")); gtk_widget_show (label); gtk_box_pack_start (GTK_BOX (vbox2), label, FALSE, FALSE, 0); - + /* save session */ if (!autosave) { @@ -415,6 +486,8 @@ { gtk_widget_set_sensitive (reboot_button, FALSE); gtk_widget_set_sensitive (halt_button, FALSE); + gtk_widget_set_sensitive (hibernate_button, FALSE); + gtk_widget_set_sensitive (suspend_button, FALSE); } /* save portion of the root window covered by the dialog */ @@ -610,7 +683,7 @@ result = xfsm_shutdown_helper_send_command (shutdown_helper, XFSM_SHUTDOWN_POWEROFF); } - else + else if (type == SHUTDOWN_REBOOT) { result = xfsm_shutdown_helper_send_command (shutdown_helper, XFSM_SHUTDOWN_REBOOT); @@ -629,3 +702,34 @@ return EXIT_SUCCESS; } + +gint +xfsm_suspend(gint type) +{ + gboolean result; + + if (shutdown_helper == NULL) + { + g_warning ("No shutdown helper attached!"); + return EXIT_FAILURE; + } + + if (type == SHUTDOWN_HIBERNATE) + { + result = xfsm_shutdown_helper_send_command (shutdown_helper, + XFSM_SHUTDOWN_HIBERNATE); + } + else if (type == SHUTDOWN_SUSPEND) + { + result = xfsm_shutdown_helper_send_command (shutdown_helper, + XFSM_SHUTDOWN_SUSPEND); + } + + if (!result) + { + g_warning ("Failed to perform suspend/hibernate action!"); + return EXIT_FAILURE; + } + + return EXIT_SUCCESS; +} diff -u'rNF^function' xfce4-session-4.3.90.2svn-r22296.orig/xfce4-session/shutdown.h xfce4-session-4.3.90.2svn-r22296/xfce4-session/shutdown.h --- xfce4-session-4.3.90.2svn-r22296.orig/xfce4-session/shutdown.h 2006-07-07 23:48:32.000000000 +0200 +++ xfce4-session-4.3.90.2svn-r22296/xfce4-session/shutdown.h 2006-07-17 21:10:04.000000000 +0200 @@ -25,9 +25,12 @@ #include /* */ -#define SHUTDOWN_LOGOUT 0 +#define SHUTDOWN_LOGOUT 0 #define SHUTDOWN_REBOOT 1 #define SHUTDOWN_HALT 2 +#define SHUTDOWN_HIBERNATE 3 +#define SHUTDOWN_SUSPEND 4 + /* prototypes */ extern gboolean shutdownDialog(gint *, gboolean *); diff -u'rNF^function' xfce4-session-4.3.90.2svn-r22296.orig/xfce4-session/xfsm-manager.c xfce4-session-4.3.90.2svn-r22296/xfce4-session/xfsm-manager.c --- xfce4-session-4.3.90.2svn-r22296.orig/xfce4-session/xfsm-manager.c 2006-07-07 23:48:32.000000000 +0200 +++ xfce4-session-4.3.90.2svn-r22296/xfce4-session/xfsm-manager.c 2006-07-29 12:38:21.000000000 +0200 @@ -802,7 +802,14 @@ { if (!fast && shutdown && !shutdownDialog (&shutdown_type, &shutdown_save)) return; - + + /* handle HIBERNATE or SUSPEND */ + if ((shutdown_type == SHUTDOWN_SUSPEND) || (shutdown_type == SHUTDOWN_HIBERNATE)) + { + xfsm_suspend(shutdown_type); + return; + } + if (!shutdown || shutdown_save) { state = shutdown ? XFSM_MANAGER_SHUTDOWN : XFSM_MANAGER_CHECKPOINT; diff -u'rNF^function' xfce4-session-4.3.90.2svn-r22296.orig/xfce4-session/xfsm-shutdown-helper-sudo.c xfce4-session-4.3.90.2svn-r22296/xfce4-session/xfsm-shutdown-helper-sudo.c --- xfce4-session-4.3.90.2svn-r22296.orig/xfce4-session/xfsm-shutdown-helper-sudo.c 2006-07-07 23:48:32.000000000 +0200 +++ xfce4-session-4.3.90.2svn-r22296/xfce4-session/xfsm-shutdown-helper-sudo.c 2006-07-17 20:52:27.000000000 +0200 @@ -273,7 +273,7 @@ xfsm_shutdown_helper_send_command (XfsmShutdownHelper *helper, XfsmShutdownCommand command) { - static char *command_table[] = { "POWEROFF", "REBOOT" }; + static char *command_table[] = { "POWEROFF", "REBOOT", "HIBERNATE", "SUSPEND" }; char response[256]; g_return_val_if_fail (helper != NULL, FALSE); diff -u'rNF^function' xfce4-session-4.3.90.2svn-r22296.orig/xfce4-session/xfsm-shutdown-helper.h xfce4-session-4.3.90.2svn-r22296/xfce4-session/xfsm-shutdown-helper.h --- xfce4-session-4.3.90.2svn-r22296.orig/xfce4-session/xfsm-shutdown-helper.h 2006-07-07 23:48:32.000000000 +0200 +++ xfce4-session-4.3.90.2svn-r22296/xfce4-session/xfsm-shutdown-helper.h 2006-07-17 21:10:25.000000000 +0200 @@ -29,6 +29,8 @@ { XFSM_SHUTDOWN_POWEROFF = 0, XFSM_SHUTDOWN_REBOOT = 1, + XFSM_SHUTDOWN_HIBERNATE = 2, + XFSM_SHUTDOWN_SUSPEND = 3, } XfsmShutdownCommand; diff -u'rNF^function' xfce4-session-4.3.90.2svn-r22296.orig/xfsm-shutdown-helper/main.c xfce4-session-4.3.90.2svn-r22296/xfsm-shutdown-helper/main.c --- xfce4-session-4.3.90.2svn-r22296.orig/xfsm-shutdown-helper/main.c 2006-07-07 23:48:33.000000000 +0200 +++ xfce4-session-4.3.90.2svn-r22296/xfsm-shutdown-helper/main.c 2006-07-19 12:26:25.000000000 +0200 @@ -61,11 +61,14 @@ #define POWEROFF_CMD "/sbin/shutdown -p now" #define REBOOT_CMD "/sbin/shutdown -r now" #else -#define POWEROFF_CMD "/sbin/shutdown -h now" -#define REBOOT_CMD "/sbin/shutdown -r now" +#define POWEROFF_CMD "/sbin/shutdown -h now" +#define REBOOT_CMD "/sbin/shutdown -r now" #endif + + + static gboolean run (const gchar *command) { @@ -139,6 +142,14 @@ { succeed = run (REBOOT_CMD); } + else if (strncasecmp (action, "HIBERNATE", 9) == 0) + { + succeed = run (HIBERNATE_CMD); + } + else if (strncasecmp (action, "SUSPEND", 7) == 0) + { + succeed = run (SUSPEND_CMD); + } if (succeed) {