summaryrefslogtreecommitdiff
path: root/settings
diff options
context:
space:
mode:
authorEric Koegel <eric.koegel@gmail.com>2015-03-22 11:14:27 +0300
committerEric Koegel <eric.koegel@gmail.com>2015-03-22 14:58:40 +0300
commit61a4c3fff1e5638e7355f575fafd1a05097bb652 (patch)
treeb020d23f81e701e2cbebe53000e3a3deab3c225d /settings
parentb724bcc115245f713300d51b0a5370b762a9f675 (diff)
downloadixfce4-power-manager-61a4c3fff1e5638e7355f575fafd1a05097bb652.tar.gz
Settings: Use a quit signal to exit
This allows the settings app to properly to exit when it's a GtkPlug.
Diffstat (limited to 'settings')
-rw-r--r--settings/xfpm-settings-app.c32
-rw-r--r--settings/xfpm-settings.c9
-rw-r--r--settings/xfpm-settings.h3
3 files changed, 41 insertions, 3 deletions
diff --git a/settings/xfpm-settings-app.c b/settings/xfpm-settings-app.c
index 017ac56c..ad6cf849 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 4e4446da..53300652 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 1e5e1a15..25e5630f 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);