Index: xfce4-session/xfsm-shutdown-helper.c =================================================================== --- xfce4-session/xfsm-shutdown-helper.c (revision 28481) +++ xfce4-session/xfsm-shutdown-helper.c (working copy) @@ -57,10 +57,20 @@ #include +#include #include +static struct +{ + XfsmShutdownCommand command; + gchar * name; +} XfsmCommand2Name[] = { + { XFSM_SHUTDOWN_HALT, "Shutdown" }, + { XFSM_SHUTDOWN_REBOOT, "Reboot" }, + { XFSM_SHUTDOWN_SUSPEND, "Suspend" }, + { XFSM_SHUTDOWN_HIBERNATE, "Hibernate" } +}; - struct _XfsmShutdownHelper { gchar *sudo; @@ -73,7 +83,7 @@ -static gboolean +gboolean xfsm_shutdown_helper_hal_check (XfsmShutdownHelper *helper) { DBusConnection *connection; @@ -144,7 +154,16 @@ DBusMessage *message; DBusMessage *result; DBusError error; + gchar *methodname; + dbus_int32_t wakeup = 0; + int i; + for (i = 0; i < G_N_ELEMENTS (XfsmCommand2Name); i++) { + if ( XfsmCommand2Name[i].command == command ) { + methodname = XfsmCommand2Name[i].name; + } + } + /* initialize the error */ dbus_error_init (&error); @@ -161,7 +180,13 @@ message = dbus_message_new_method_call ("org.freedesktop.Hal", "/org/freedesktop/Hal/devices/computer", "org.freedesktop.Hal.Device.SystemPowerManagement", - (command == XFSM_SHUTDOWN_COMMAND_REBOOT) ? "Reboot" : "Shutdown"); + methodname); + + /* suspend requires additional arguements */ + if (command == XFSM_SHUTDOWN_SUSPEND) { + dbus_message_append_args (message, DBUS_TYPE_INT32, &wakeup, DBUS_TYPE_INVALID); + } + result = dbus_connection_send_with_reply_and_block (connection, message, 2000, &error); dbus_message_unref (message); Index: xfce4-session/xfsm-shutdown-helper.h =================================================================== --- xfce4-session/xfsm-shutdown-helper.h (revision 28481) +++ xfce4-session/xfsm-shutdown-helper.h (working copy) @@ -37,6 +37,8 @@ XfsmShutdownHelper *xfsm_shutdown_helper_spawn (void); +gboolean xfsm_shutdown_helper_hal_check (XfsmShutdownHelper *helper); + gboolean xfsm_shutdown_helper_need_password (const XfsmShutdownHelper *helper); gboolean xfsm_shutdown_helper_send_password (XfsmShutdownHelper *helper, Index: xfce4-session/shutdown.c =================================================================== --- xfce4-session/shutdown.c (revision 28481) +++ xfce4-session/shutdown.c (working copy) @@ -138,6 +138,22 @@ gtk_dialog_response (GTK_DIALOG (shutdown_dialog), GTK_RESPONSE_OK); } +static void +suspend_button_clicked (GtkWidget *b, gint *shutdownType) +{ + *shutdownType = XFSM_SHUTDOWN_SUSPEND; + + gtk_dialog_response (GTK_DIALOG (shutdown_dialog), GTK_RESPONSE_OK); +} + +static void +hibernate_button_clicked (GtkWidget *b, gint *shutdownType) +{ + *shutdownType = XFSM_SHUTDOWN_HIBERNATE; + + gtk_dialog_response (GTK_DIALOG (shutdown_dialog), GTK_RESPONSE_OK); +} + /* */ gboolean @@ -160,12 +176,16 @@ GtkWidget *logout_button; GtkWidget *reboot_button; GtkWidget *halt_button; + GtkWidget *suspend_button; + GtkWidget *hibernate_button; GtkWidget *cancel_button; GtkWidget *ok_button; GdkPixbuf *icon; gboolean saveonexit; gboolean autosave; gboolean prompt; + gboolean have_suspend; + gboolean have_hibernate; gint monitor; gint result; XfceKiosk *kiosk; @@ -199,6 +219,8 @@ saveonexit = xfconf_channel_get_bool (channel, "/general/SaveOnExit", TRUE); autosave = xfconf_channel_get_bool (channel, "/general/AutoSave", FALSE); prompt = xfconf_channel_get_bool (channel, "/general/PromptOnLogout", TRUE); + have_suspend = xfconf_channel_get_bool (channel, "/general/HaveSuspend", TRUE); + have_hibernate = xfconf_channel_get_bool (channel, "/general/HaveHibernate", TRUE); /* if PromptOnLogout is off, saving depends on AutoSave */ if (!prompt) @@ -339,6 +361,60 @@ gtk_widget_show (label); gtk_box_pack_start (GTK_BOX (vbox2), label, FALSE, FALSE, 0); + /* suspend */ + if (have_suspend) { + suspend_button = gtk_button_new (); + gtk_widget_show (suspend_button); + 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 ("system-suspend", 32); + if (!icon) + 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); + } + + /* hibernate */ + if (have_hibernate) { + hibernate_button = gtk_button_new (); + gtk_widget_show (hibernate_button); + 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 ("system-hibernate", 32); + if (!icon) + 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); + } + /* reboot */ reboot_button = gtk_button_new (); gtk_widget_show (reboot_button); @@ -388,7 +464,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) { @@ -616,17 +692,8 @@ return EXIT_FAILURE; } - if (type == XFSM_SHUTDOWN_HALT) - { - result = xfsm_shutdown_helper_send_command (shutdown_helper, - XFSM_SHUTDOWN_COMMAND_POWEROFF); - } - else - { - result = xfsm_shutdown_helper_send_command (shutdown_helper, - XFSM_SHUTDOWN_COMMAND_REBOOT); - } - + result = xfsm_shutdown_helper_send_command (shutdown_helper, + type); xfsm_shutdown_helper_destroy (shutdown_helper); shutdown_helper = NULL; Index: xfce4-session/shutdown.h =================================================================== --- xfce4-session/shutdown.h (revision 28481) +++ xfce4-session/shutdown.h (working copy) @@ -32,7 +32,7 @@ XFSM_SHUTDOWN_HALT, XFSM_SHUTDOWN_REBOOT, XFSM_SHUTDOWN_SUSPEND, - XFSM_SHUTDOWN_HIBERNATE, + XFSM_SHUTDOWN_HIBERNATE } XfsmShutdownType; /* prototypes */ Index: xfce4-session/xfsm-manager.c =================================================================== --- xfce4-session/xfsm-manager.c (revision 28481) +++ xfce4-session/xfsm-manager.c (working copy) @@ -73,6 +73,7 @@ #include +#include #include #include @@ -1075,6 +1076,27 @@ if (!shutdownDialog (manager->session_name, &manager->shutdown_type, &shutdown_save)) return; + /* we only save the session if we're actually closing shop */ + /* if we are suspending, hibrenating, or switching users, */ + /* the session hasn't actually ended. */ + if (manager->shutdown_type != XFSM_SHUTDOWN_HALT || manager->shutdown_type != XFSM_SHUTDOWN_REBOOT) + { + XfsmShutdownHelper* shutdown_helper = xfsm_shutdown_helper_spawn(); + + /* Check for hal */ + if (xfsm_shutdown_helper_hal_check(&shutdown_helper) == FALSE) + { + g_warning("DBus not available. Suspend/Hibrenate not available."); + return; + } + + /* send the suspend/hibrenate message */ + xfsm_shutdown_helper_send_command(shutdown_helper, manager->shutdown_type); + + /* clean up and return */ + xfsm_shutdown_helper_destroy(shutdown_helper); + return; + } /* |allow_shutdown_save| is ignored if we prompt the user. i think * this is the right thing to do. */ } @@ -1872,13 +1894,6 @@ return FALSE; } - if (type == XFSM_SHUTDOWN_SUSPEND || type == XFSM_SHUTDOWN_HIBERNATE) - { - g_set_error (error, XFSM_ERROR, XFSM_ERROR_UNSUPPORTED, - _("Suspend and hibernate are not supported")); - return FALSE; - } - if (type > XFSM_SHUTDOWN_HIBERNATE) { g_set_error (error, XFSM_ERROR, XFSM_ERROR_BAD_VALUE, Index: xfce4-session-logout/main.c =================================================================== --- xfce4-session-logout/main.c (revision 28481) +++ xfce4-session-logout/main.c (working copy) @@ -51,7 +51,7 @@ XFSM_SHUTDOWN_HALT, XFSM_SHUTDOWN_REBOOT, XFSM_SHUTDOWN_SUSPEND, - XFSM_SHUTDOWN_HIBERNATE, + XFSM_SHUTDOWN_HIBERNATE, } XfsmShutdownType;