[Xfce4-commits] [xfce/xfce4-power-manager] 62/63: Settings: Use a quit signal to exit
noreply at xfce.org
noreply at xfce.org
Sun Mar 22 13:02:57 CET 2015
This is an automated email from the git hooks/post-receive script.
eric pushed a commit to branch master
in repository xfce/xfce4-power-manager.
commit 61a4c3fff1e5638e7355f575fafd1a05097bb652
Author: Eric Koegel <eric.koegel at gmail.com>
Date: Sun Mar 22 11:14:27 2015 +0300
Settings: Use a quit signal to exit
This allows the settings app to properly to exit when it's a
GtkPlug.
---
settings/xfpm-settings-app.c | 32 +++++++++++++++++++++++++++++++-
settings/xfpm-settings.c | 9 ++++++++-
settings/xfpm-settings.h | 3 ++-
3 files changed, 41 insertions(+), 3 deletions(-)
diff --git a/settings/xfpm-settings-app.c b/settings/xfpm-settings-app.c
index 017ac56..ad6cf84 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 4e4446d..5330065 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 1e5e1a1..25e5630 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);
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Xfce4-commits
mailing list