diff --git a/settings/xfpm-settings-app.c b/settings/xfpm-settings-app.c index 017ac56c0c8340951e23d1f7c70fb901fee1042b..ad6cf84913381a87feeae7127cf40495beebd9a9 100644 --- a/settings/xfpm-settings-app.c +++ b/settings/xfpm-settings-app.c @@ -59,6 +59,9 @@ static void activate_debug (GSimpleAction *action, static void activate_window (GSimpleAction *action, GVariant *parameter, gpointer data); +static void activate_quit (GSimpleAction *action, + GVariant *parameter, + gpointer data); G_DEFINE_TYPE(XfpmSettingsApp, xfpm_settings_app, GTK_TYPE_APPLICATION); @@ -74,6 +77,7 @@ xfpm_settings_app_init (XfpmSettingsApp *app) { "device-id", 'd', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_STRING, NULL, N_("Display a specific device by UpDevice object path"), N_("UpDevice object path") }, { "debug", '\0', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, NULL, N_("Enable debugging"), NULL }, { "version", 'V', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, NULL, N_("Display version information"), NULL }, + { "quit", 'q', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, NULL, N_("Cause xfce4-power-manager-settings to quit"), NULL }, { NULL, }, }; @@ -88,6 +92,7 @@ xfpm_settings_app_startup (GApplication *app) { "device-id", activate_device, "s" }, { "debug", activate_debug, NULL }, { "activate", activate_window, NULL }, + { "quit", activate_quit, NULL }, }; TRACE ("entering"); @@ -243,7 +248,7 @@ xfpm_settings_app_launch (GApplication *app) dialog = xfpm_settings_dialog_new (channel, auth_suspend, auth_hibernate, can_suspend, can_hibernate, can_shutdown, has_battery, has_lcd_brightness, has_lid, has_sleep_button, has_hibernate_button, has_power_button, - priv->socket_id, priv->device_id); + priv->socket_id, priv->device_id, GTK_APPLICATION (app)); g_hash_table_destroy (hash); @@ -310,6 +315,25 @@ activate_window (GSimpleAction *action, xfpm_settings_app_launch (G_APPLICATION (app)); } +static void +activate_quit (GSimpleAction *action, + GVariant *parameter, + gpointer data) +{ + GtkApplication *app = GTK_APPLICATION (data); + GList *windows; + + TRACE ("entering"); + + windows = gtk_application_get_windows (app); + + if (windows) + { + /* Remove our window if we've attahced one */ + gtk_application_remove_window (app, GTK_WINDOW (windows->data)); + } +} + static gboolean xfpm_settings_app_local_options (GApplication *g_application, GVariantDict *options) @@ -361,6 +385,12 @@ xfpm_settings_app_local_options (GApplication *g_application, return 0; } + /* --quit */ + if (g_variant_dict_contains (options, "quit") || g_variant_dict_contains (options, "q")) + { + g_action_group_activate_action(G_ACTION_GROUP(g_application), "quit", NULL); + return 0; + } /* default action */ g_action_group_activate_action(G_ACTION_GROUP(g_application), "activate", NULL); diff --git a/settings/xfpm-settings.c b/settings/xfpm-settings.c index 4e4446da5cc743d197d28ac3a4f1285249e462c2..533006526db5e4793b5dd1b592337566e6199147 100644 --- a/settings/xfpm-settings.c +++ b/settings/xfpm-settings.c @@ -51,6 +51,7 @@ #define BRIGHTNESS_DISABLED 9 +static GtkApplication *app = NULL; static GtkBuilder *xml = NULL; static GtkWidget *nt = NULL; @@ -2146,6 +2147,8 @@ settings_quit (GtkWidget *widget, XfconfChannel *channel) g_object_unref (channel); xfconf_shutdown(); gtk_widget_destroy (widget); + /* initiate the quit action on the application so it terminates */ + g_action_group_activate_action(G_ACTION_GROUP(app), "quit", NULL); } static void dialog_response_cb (GtkDialog *dialog, gint response, XfconfChannel *channel) @@ -2174,7 +2177,7 @@ xfpm_settings_dialog_new (XfconfChannel *channel, gboolean auth_suspend, gboolean has_battery, gboolean has_lcd_brightness, gboolean has_lid, gboolean has_sleep_button, gboolean has_hibernate_button, gboolean has_power_button, - Window id, gchar *device_id) + Window id, gchar *device_id, GtkApplication *gtk_app) { GtkWidget *plug; GtkWidget *parent; @@ -2384,6 +2387,10 @@ xfpm_settings_dialog_new (XfconfChannel *channel, gboolean auth_suspend, gtk_notebook_set_current_page (GTK_NOTEBOOK (nt), devices_page_num); } + /* keep a pointer to the GtkApplication instance so we can signal a + * quit message */ + app = gtk_app; + return dialog; } diff --git a/settings/xfpm-settings.h b/settings/xfpm-settings.h index 1e5e1a15dcdbf167a06a61bc7f7cf83d9fa887ec..25e5630f4938e56697ba60da468af9933d77b543 100644 --- a/settings/xfpm-settings.h +++ b/settings/xfpm-settings.h @@ -37,7 +37,8 @@ GtkWidget *xfpm_settings_dialog_new (XfconfChannel *channel, gboolean has_hibernate_button, gboolean has_power_button, Window id, - gchar *device_id); + gchar *device_id, + GtkApplication *gtk_app); void xfpm_settings_show_device_id (gchar *device_id);