diff --git a/shell/control-center.c b/shell/control-center.c index be23207ef..ece261b6b 100644 --- a/shell/control-center.c +++ b/shell/control-center.c @@ -28,57 +28,16 @@ #include #include + static void -application_prepare_action_cb (GApplication *application, - GVariant *arguments, - GVariant *platform_data, - GnomeControlCenter *shell) +application_command_line_cb (GApplication *application, + GApplicationCommandLine *command_line, + GnomeControlCenter *shell) { - const gchar **argv; - gsize length; - - gnome_control_center_present (shell); - - argv = g_variant_get_bytestring_array (arguments, &length); - - if (length == 2) - { - GError *err = NULL; - const gchar *id = argv[1]; - - if (!cc_shell_set_active_panel_from_id (CC_SHELL (shell), id, &err)) - { - if (err) - { - g_warning ("Could not load setting panel \"%s\": %s", id, - err->message); - g_error_free (err); - } - } - } -} - -int -main (int argc, char **argv) -{ - GnomeControlCenter *shell; - GtkApplication *application; - - bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR); - bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); - textdomain (GETTEXT_PACKAGE); - - - g_thread_init (NULL); - gtk_init (&argc, &argv); - - shell = gnome_control_center_new (); - - /* enforce single instance of this application */ - application = gtk_application_new ("org.gnome.ControlCenter", &argc, &argv); - g_signal_connect (application, "prepare-activation", - G_CALLBACK (application_prepare_action_cb), shell); + int argc; + char **argv; + g_application_command_line_get_argc_argv (command_line, &argc, &argv); if (argc == 2) { gchar *start_id; @@ -97,11 +56,44 @@ main (int argc, char **argv) } } } + g_strfreev (argv); +} - gtk_application_run (application); +static void +application_startup_cb (GApplication *application, + GnomeControlCenter *shell) +{ + gnome_control_center_show (shell, GTK_APPLICATION (application)); + gnome_control_center_present (shell); +} + +int +main (int argc, char **argv) +{ + GnomeControlCenter *shell; + GtkApplication *application; + int status; + + bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR); + bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); + textdomain (GETTEXT_PACKAGE); + + + g_thread_init (NULL); + gtk_init (&argc, &argv); + + shell = gnome_control_center_new (); + + /* enforce single instance of this application */ + application = gtk_application_new ("org.gnome.ControlCenter", G_APPLICATION_HANDLES_COMMAND_LINE); + g_signal_connect (application, "startup", + G_CALLBACK (application_startup_cb), shell); + g_signal_connect (application, "command-line", + G_CALLBACK (application_command_line_cb), shell); + + status = g_application_run (G_APPLICATION (application), argc, argv); - g_object_unref (shell); g_object_unref (application); - return 0; + return status; } diff --git a/shell/gnome-control-center.c b/shell/gnome-control-center.c index 5f4d3e3f0..0ce084443 100644 --- a/shell/gnome-control-center.c +++ b/shell/gnome-control-center.c @@ -874,7 +874,6 @@ gnome_control_center_finalize (GObject *object) { GnomeControlCenterPrivate *priv = GNOME_CONTROL_CENTER (object)->priv; - if (priv->filter_string) { g_free (priv->filter_string); @@ -950,8 +949,7 @@ gnome_control_center_init (GnomeControlCenter *self) /* connect various signals */ priv->window = W (priv->builder, "main-window"); - g_signal_connect (priv->window, "delete-event", G_CALLBACK (gtk_main_quit), - NULL); + g_signal_connect_swapped (priv->window, "delete-event", G_CALLBACK (g_object_unref), self); priv->notebook = W (priv->builder, "notebook"); @@ -981,9 +979,6 @@ gnome_control_center_init (GnomeControlCenter *self) /* setup search functionality */ setup_search (self); - - gtk_widget_show_all (priv->window); - /* store default window title and name */ priv->default_window_title = g_strdup (gtk_window_get_title (GTK_WINDOW (priv->window))); priv->default_window_icon = g_strdup (gtk_window_get_icon_name (GTK_WINDOW (priv->window))); @@ -1000,3 +995,11 @@ gnome_control_center_present (GnomeControlCenter *center) { gtk_window_present (GTK_WINDOW (center->priv->window)); } + +void +gnome_control_center_show (GnomeControlCenter *center, + GtkApplication *app) +{ + gtk_window_set_application (GTK_WINDOW (center->priv->window), app); + gtk_widget_show_all (center->priv->window); +} diff --git a/shell/gnome-control-center.h b/shell/gnome-control-center.h index 09ba5de1b..10a4c3529 100644 --- a/shell/gnome-control-center.h +++ b/shell/gnome-control-center.h @@ -70,6 +70,8 @@ GnomeControlCenter *gnome_control_center_new (void); void gnome_control_center_present (GnomeControlCenter *center); +void gnome_control_center_show (GnomeControlCenter *center, GtkApplication *app); + G_END_DECLS #endif /* _GNOME_CONTROL_CENTER_H */