wmshutdown: Add support for suspend and hibernate.
This commit is contained in:
parent
eaa934f12a
commit
6b2a8dc61a
|
@ -24,21 +24,34 @@
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define GTK_RESPONSE_HALT 1
|
enum {
|
||||||
#define GTK_RESPONSE_REBOOT 2
|
GTK_RESPONSE_HALT,
|
||||||
|
GTK_RESPONSE_REBOOT,
|
||||||
|
GTK_RESPONSE_SUSPEND,
|
||||||
|
GTK_RESPONSE_HIBERNATE
|
||||||
|
};
|
||||||
|
|
||||||
#define HALT_METHOD "PowerOff"
|
#define HALT_METHOD "PowerOff"
|
||||||
#define REBOOT_METHOD "Reboot"
|
#define REBOOT_METHOD "Reboot"
|
||||||
|
#define SUSPEND_METHOD "Suspend"
|
||||||
|
#define HIBERNATE_METHOD "Hibernate"
|
||||||
#define DBUS_PATH "/org/freedesktop/login1"
|
#define DBUS_PATH "/org/freedesktop/login1"
|
||||||
#define DBUS_INTERFACE "org.freedesktop.login1.Manager"
|
#define DBUS_INTERFACE "org.freedesktop.login1.Manager"
|
||||||
#define DBUS_DESTINATION "org.freedesktop.login1"
|
#define DBUS_DESTINATION "org.freedesktop.login1"
|
||||||
|
|
||||||
static int showVersion;
|
static int showVersion;
|
||||||
|
static gboolean show_suspend = FALSE;
|
||||||
|
static gboolean show_hibernate = FALSE;
|
||||||
|
|
||||||
GtkWidget *dialog = NULL;
|
GtkWidget *dialog = NULL;
|
||||||
|
|
||||||
static GOptionEntry entries[] = {
|
static GOptionEntry entries[] = {
|
||||||
{ "version", 'v', 0, G_OPTION_ARG_NONE, &showVersion,
|
{ "version", 'v', 0, G_OPTION_ARG_NONE, &showVersion,
|
||||||
"Display version information", NULL },
|
"Display version information", NULL },
|
||||||
|
{ "suspend", 's', 0, G_OPTION_ARG_NONE, &show_suspend,
|
||||||
|
"Show 'suspend' button", NULL },
|
||||||
|
{ "hibernate", 'b', 0, G_OPTION_ARG_NONE, &show_hibernate,
|
||||||
|
"Show 'hibernate' button", NULL },
|
||||||
{ NULL }
|
{ NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -140,6 +153,8 @@ void button_press(GtkWidget *widget, GdkEvent *event)
|
||||||
GtkWidget *label;
|
GtkWidget *label;
|
||||||
GtkWidget *halt_button;
|
GtkWidget *halt_button;
|
||||||
GtkWidget *reboot_button;
|
GtkWidget *reboot_button;
|
||||||
|
GtkWidget *suspend_button;
|
||||||
|
GtkWidget *hibernate_button;
|
||||||
GtkWidget *cancel_button;
|
GtkWidget *cancel_button;
|
||||||
GdkEventButton *bevent;
|
GdkEventButton *bevent;
|
||||||
|
|
||||||
|
@ -158,23 +173,13 @@ void button_press(GtkWidget *widget, GdkEvent *event)
|
||||||
|
|
||||||
gtk_dialog_add_buttons(GTK_DIALOG(dialog),
|
gtk_dialog_add_buttons(GTK_DIALOG(dialog),
|
||||||
"Halt", GTK_RESPONSE_HALT,
|
"Halt", GTK_RESPONSE_HALT,
|
||||||
"Reboot", GTK_RESPONSE_REBOOT,
|
"Reboot", GTK_RESPONSE_REBOOT, NULL);
|
||||||
"Cancel", GTK_RESPONSE_CANCEL, NULL);
|
|
||||||
halt_button = gtk_dialog_get_widget_for_response(
|
halt_button = gtk_dialog_get_widget_for_response(
|
||||||
GTK_DIALOG(dialog),
|
GTK_DIALOG(dialog),
|
||||||
GTK_RESPONSE_HALT);
|
GTK_RESPONSE_HALT);
|
||||||
reboot_button = gtk_dialog_get_widget_for_response(
|
reboot_button = gtk_dialog_get_widget_for_response(
|
||||||
GTK_DIALOG(dialog),
|
GTK_DIALOG(dialog),
|
||||||
GTK_RESPONSE_REBOOT);
|
GTK_RESPONSE_REBOOT);
|
||||||
cancel_button = gtk_dialog_get_widget_for_response(
|
|
||||||
GTK_DIALOG(dialog),
|
|
||||||
GTK_RESPONSE_CANCEL);
|
|
||||||
|
|
||||||
g_signal_connect(dialog, "destroy", G_CALLBACK(fecha), NULL);
|
|
||||||
g_signal_connect(cancel_button,
|
|
||||||
"clicked",
|
|
||||||
G_CALLBACK(fecha),
|
|
||||||
(gpointer) dialog);
|
|
||||||
g_signal_connect(halt_button,
|
g_signal_connect(halt_button,
|
||||||
"clicked",
|
"clicked",
|
||||||
G_CALLBACK(handle_click),
|
G_CALLBACK(handle_click),
|
||||||
|
@ -183,6 +188,41 @@ void button_press(GtkWidget *widget, GdkEvent *event)
|
||||||
"clicked",
|
"clicked",
|
||||||
G_CALLBACK(handle_click),
|
G_CALLBACK(handle_click),
|
||||||
REBOOT_METHOD);
|
REBOOT_METHOD);
|
||||||
|
|
||||||
|
if (show_suspend) {
|
||||||
|
gtk_dialog_add_buttons(GTK_DIALOG(dialog), "Suspend",
|
||||||
|
GTK_RESPONSE_SUSPEND, NULL);
|
||||||
|
suspend_button =
|
||||||
|
gtk_dialog_get_widget_for_response(GTK_DIALOG(dialog),
|
||||||
|
GTK_RESPONSE_SUSPEND);
|
||||||
|
g_signal_connect(suspend_button,
|
||||||
|
"clicked",
|
||||||
|
G_CALLBACK(handle_click),
|
||||||
|
SUSPEND_METHOD);
|
||||||
|
}
|
||||||
|
if (show_hibernate) {
|
||||||
|
gtk_dialog_add_buttons(GTK_DIALOG(dialog), "Hibernate",
|
||||||
|
GTK_RESPONSE_HIBERNATE, NULL);
|
||||||
|
hibernate_button =
|
||||||
|
gtk_dialog_get_widget_for_response(GTK_DIALOG(dialog),
|
||||||
|
GTK_RESPONSE_HIBERNATE);
|
||||||
|
g_signal_connect(hibernate_button,
|
||||||
|
"clicked",
|
||||||
|
G_CALLBACK(handle_click),
|
||||||
|
HIBERNATE_METHOD);
|
||||||
|
}
|
||||||
|
|
||||||
|
gtk_dialog_add_buttons(GTK_DIALOG(dialog), "Cancel",
|
||||||
|
GTK_RESPONSE_CANCEL, NULL);
|
||||||
|
cancel_button = gtk_dialog_get_widget_for_response(
|
||||||
|
GTK_DIALOG(dialog),
|
||||||
|
GTK_RESPONSE_CANCEL);
|
||||||
|
g_signal_connect(cancel_button,
|
||||||
|
"clicked",
|
||||||
|
G_CALLBACK(fecha),
|
||||||
|
(gpointer) dialog);
|
||||||
|
|
||||||
|
g_signal_connect(dialog, "destroy", G_CALLBACK(fecha), NULL);
|
||||||
gtk_widget_show_all(dialog);
|
gtk_widget_show_all(dialog);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
Loading…
Reference in a new issue