Commit b80390d0 authored by Carlos Soriano Sánchez's avatar Carlos Soriano Sánchez

desktop: move to a different binary

We wanted to do this for long time. This will allow to handle the
desktop process in a different binary.
The ultimate goal is to make the desktop code completely split from
nautilus code.

This is the first and minimal step towards that goal.

In this patch we create a desktop application separated from nautilus
application, and remove the desktop handling in nautilus application.

https://bugzilla.gnome.org/show_bug.cgi?id=712620
parent 23ae5387
[Desktop Entry] [Desktop Entry]
Type=Application Type=Application
Name=Files Name=Files
Exec=nautilus -n Exec=nautilus-desktop
OnlyShowIn=GNOME;Unity; OnlyShowIn=GNOME;Unity;
AutostartCondition=GSettings org.gnome.desktop.background show-desktop-icons AutostartCondition=GSettings org.gnome.desktop.background show-desktop-icons
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
Type=Application Type=Application
Name=Desktop Icons Name=Desktop Icons
Comment=Classic session desktop file for desktop icons Comment=Classic session desktop file for desktop icons
Exec=nautilus --no-default-window --force-desktop Exec=nautilus-desktop
OnlyShowIn=GNOME; OnlyShowIn=GNOME;
NoDisplay=true NoDisplay=true
X-GNOME-Bugzilla-Bugzilla=GNOME X-GNOME-Bugzilla-Bugzilla=GNOME
......
...@@ -2,6 +2,7 @@ include $(top_srcdir)/Makefile.shared ...@@ -2,6 +2,7 @@ include $(top_srcdir)/Makefile.shared
bin_PROGRAMS= \ bin_PROGRAMS= \
nautilus \ nautilus \
nautilus-desktop \
nautilus-autorun-software \ nautilus-autorun-software \
$(NULL) $(NULL)
...@@ -134,7 +135,7 @@ nautilus_built_sources = \ ...@@ -134,7 +135,7 @@ nautilus_built_sources = \
nautilus-enum-types.c \ nautilus-enum-types.c \
$(NULL) $(NULL)
nautilus_SOURCES = \ nautilus_no_main_sources = \
gtk/nautilusgtkplacesview.c \ gtk/nautilusgtkplacesview.c \
gtk/nautilusgtkplacesviewprivate.h \ gtk/nautilusgtkplacesviewprivate.h \
gtk/nautilusgtkplacesviewrow.c \ gtk/nautilusgtkplacesviewrow.c \
...@@ -178,7 +179,6 @@ nautilus_SOURCES = \ ...@@ -178,7 +179,6 @@ nautilus_SOURCES = \
nautilus-list-view-dnd.h \ nautilus-list-view-dnd.h \
nautilus-location-entry.c \ nautilus-location-entry.c \
nautilus-location-entry.h \ nautilus-location-entry.h \
nautilus-main.c \
nautilus-mime-actions.c \ nautilus-mime-actions.c \
nautilus-mime-actions.h \ nautilus-mime-actions.h \
nautilus-notebook.c \ nautilus-notebook.c \
...@@ -221,10 +221,26 @@ nautilus_SOURCES = \ ...@@ -221,10 +221,26 @@ nautilus_SOURCES = \
nautilus-x-content-bar.h \ nautilus-x-content-bar.h \
$(NULL) $(NULL)
nautilus_SOURCES = \
$(nautilus_no_main_sources) \
nautilus-main.c \
$(NULL)
nautilus_desktop_SOURCES= \
$(nautilus_no_main_sources) \
main-desktop.c \
nautilus-desktop-application.c \
nautilus-desktop-application.h \
$(NULL)
nodist_nautilus_SOURCES = \ nodist_nautilus_SOURCES = \
$(nautilus_built_sources) \ $(nautilus_built_sources) \
$(NULL) $(NULL)
nodist_nautilus_desktop_SOURCES = \
$(nautilus_built_sources) \
$(NULL)
EMPTY_VIEW_SOURCES = \ EMPTY_VIEW_SOURCES = \
nautilus-empty-view.c \ nautilus-empty-view.c \
nautilus-empty-view.h nautilus-empty-view.h
......
#include <config.h>
#include "nautilus-desktop-application.h"
#include <glib/gi18n.h>
#include <gtk/gtk.h>
#include <gio/gdesktopappinfo.h>
#include <libxml/parser.h>
#ifdef HAVE_LOCALE_H
#include <locale.h>
#endif
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
int
main (int argc, char *argv[])
{
NautilusDesktopApplication *application;
int retval;
/* Initialize gettext support */
bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
textdomain (GETTEXT_PACKAGE);
g_set_prgname ("nautilus-desktop");
application = nautilus_desktop_application_new ();
retval = g_application_run (G_APPLICATION (application),
argc, argv);
g_object_unref (application);
return retval;
}
...@@ -29,7 +29,6 @@ ...@@ -29,7 +29,6 @@
#include "nautilus-application.h" #include "nautilus-application.h"
#include "nautilus-dbus-manager.h" #include "nautilus-dbus-manager.h"
#include "nautilus-desktop-window.h"
#include "nautilus-freedesktop-dbus.h" #include "nautilus-freedesktop-dbus.h"
#include "nautilus-image-properties-page.h" #include "nautilus-image-properties-page.h"
#include "nautilus-previewer.h" #include "nautilus-previewer.h"
...@@ -70,8 +69,6 @@ typedef struct { ...@@ -70,8 +69,6 @@ typedef struct {
NautilusDBusManager *dbus_manager; NautilusDBusManager *dbus_manager;
NautilusFreedesktopDBus *fdb_manager; NautilusFreedesktopDBus *fdb_manager;
gboolean desktop_override;
NautilusBookmarkList *bookmark_list; NautilusBookmarkList *bookmark_list;
NautilusShellSearchProvider *search_provider; NautilusShellSearchProvider *search_provider;
...@@ -124,7 +121,6 @@ static gboolean ...@@ -124,7 +121,6 @@ static gboolean
check_required_directories (NautilusApplication *self) check_required_directories (NautilusApplication *self)
{ {
char *user_directory; char *user_directory;
char *desktop_directory;
GSList *directories; GSList *directories;
gboolean ret; gboolean ret;
...@@ -135,7 +131,6 @@ check_required_directories (NautilusApplication *self) ...@@ -135,7 +131,6 @@ check_required_directories (NautilusApplication *self)
ret = TRUE; ret = TRUE;
user_directory = nautilus_get_user_directory (); user_directory = nautilus_get_user_directory ();
desktop_directory = nautilus_get_desktop_directory ();
directories = NULL; directories = NULL;
...@@ -143,10 +138,6 @@ check_required_directories (NautilusApplication *self) ...@@ -143,10 +138,6 @@ check_required_directories (NautilusApplication *self)
directories = g_slist_prepend (directories, user_directory); directories = g_slist_prepend (directories, user_directory);
} }
if (!g_file_test (desktop_directory, G_FILE_TEST_IS_DIR)) {
directories = g_slist_prepend (directories, desktop_directory);
}
if (directories != NULL) { if (directories != NULL) {
int failed_count; int failed_count;
GString *directories_as_string; GString *directories_as_string;
...@@ -187,7 +178,6 @@ check_required_directories (NautilusApplication *self) ...@@ -187,7 +178,6 @@ check_required_directories (NautilusApplication *self)
g_slist_free (directories); g_slist_free (directories);
g_free (user_directory); g_free (user_directory);
g_free (desktop_directory);
nautilus_profile_end (NULL); nautilus_profile_end (NULL);
return ret; return ret;
...@@ -389,22 +379,6 @@ real_open_location_full (NautilusApplication *self, ...@@ -389,22 +379,6 @@ real_open_location_full (NautilusApplication *self,
if (target_slot != NULL) if (target_slot != NULL)
target_window = nautilus_window_slot_get_window (target_slot); target_window = nautilus_window_slot_get_window (target_slot);
if ((target_window && NAUTILUS_IS_DESKTOP_WINDOW (target_window)) ||
(!target_window && NAUTILUS_IS_DESKTOP_WINDOW (active_window))) {
NautilusWindow *desktop_target_window;
desktop_target_window = target_window ? target_window : active_window;
use_same = !nautilus_desktop_window_loaded (NAUTILUS_DESKTOP_WINDOW (desktop_target_window));
/* if we're requested to open a new tab on the desktop, open a window
* instead.
*/
if (flags & NAUTILUS_WINDOW_OPEN_FLAG_NEW_TAB) {
flags ^= NAUTILUS_WINDOW_OPEN_FLAG_NEW_TAB;
flags |= NAUTILUS_WINDOW_OPEN_FLAG_NEW_WINDOW;
}
}
g_assert (!((flags & NAUTILUS_WINDOW_OPEN_FLAG_NEW_WINDOW) != 0 && g_assert (!((flags & NAUTILUS_WINDOW_OPEN_FLAG_NEW_WINDOW) != 0 &&
(flags & NAUTILUS_WINDOW_OPEN_FLAG_NEW_TAB) != 0)); (flags & NAUTILUS_WINDOW_OPEN_FLAG_NEW_TAB) != 0));
...@@ -433,16 +407,14 @@ real_open_location_full (NautilusApplication *self, ...@@ -433,16 +407,14 @@ real_open_location_full (NautilusApplication *self,
/* close the current window if the flags say so */ /* close the current window if the flags say so */
if ((flags & NAUTILUS_WINDOW_OPEN_FLAG_CLOSE_BEHIND) != 0) { if ((flags & NAUTILUS_WINDOW_OPEN_FLAG_CLOSE_BEHIND) != 0) {
if (!NAUTILUS_IS_DESKTOP_WINDOW (active_window)) { if (gtk_widget_get_visible (GTK_WIDGET (target_window))) {
if (gtk_widget_get_visible (GTK_WIDGET (target_window))) { nautilus_window_close (active_window);
nautilus_window_close (active_window); } else {
} else { g_signal_connect_object (target_window,
g_signal_connect_object (target_window, "show",
"show", G_CALLBACK (new_window_show_callback),
G_CALLBACK (new_window_show_callback), active_window,
active_window, G_CONNECT_AFTER);
G_CONNECT_AFTER);
}
} }
} }
...@@ -598,13 +570,6 @@ do_cmdline_sanity_checks (NautilusApplication *self, ...@@ -598,13 +570,6 @@ do_cmdline_sanity_checks (NautilusApplication *self,
goto out; goto out;
} }
if (g_variant_dict_contains (options, "force-desktop") &&
g_variant_dict_contains (options, "no-desktop")) {
g_printerr ("%s\n",
_("--no-desktop and --force-desktop cannot be used together."));
goto out;
}
retval = TRUE; retval = TRUE;
out: out:
...@@ -726,27 +691,6 @@ action_help (GSimpleAction *action, ...@@ -726,27 +691,6 @@ action_help (GSimpleAction *action,
} }
} }
static void
action_open_desktop (GSimpleAction *action,
GVariant *parameter,
gpointer user_data)
{
nautilus_desktop_window_ensure ();
}
static void
action_close_desktop (GSimpleAction *action,
GVariant *parameter,
gpointer user_data)
{
GtkWidget *desktop_window;
desktop_window = nautilus_desktop_window_get ();
if (desktop_window != NULL) {
gtk_widget_destroy (desktop_window);
}
}
static void static void
action_kill (GSimpleAction *action, action_kill (GSimpleAction *action,
GVariant *parameter, GVariant *parameter,
...@@ -766,7 +710,6 @@ action_quit (GSimpleAction *action, ...@@ -766,7 +710,6 @@ action_quit (GSimpleAction *action,
NautilusApplication *self = NAUTILUS_APPLICATION (user_data); NautilusApplication *self = NAUTILUS_APPLICATION (user_data);
GList *windows, *l; GList *windows, *l;
/* nautilus_window_close() doesn't do anything for desktop windows */
windows = nautilus_application_get_windows (self); windows = nautilus_application_get_windows (self);
/* make a copy, since the original list will be modified when destroying /* make a copy, since the original list will be modified when destroying
* a window, making this list invalid */ * a window, making this list invalid */
...@@ -817,8 +760,6 @@ static GActionEntry app_entries[] = { ...@@ -817,8 +760,6 @@ static GActionEntry app_entries[] = {
{ "help", action_help, NULL, NULL, NULL }, { "help", action_help, NULL, NULL, NULL },
{ "quit", action_quit, NULL, NULL, NULL }, { "quit", action_quit, NULL, NULL, NULL },
{ "kill", action_kill, NULL, NULL, NULL }, { "kill", action_kill, NULL, NULL, NULL },
{ "open-desktop", action_open_desktop, NULL, NULL, NULL },
{ "close-desktop", action_close_desktop, NULL, NULL, NULL },
{ "show-help-overlay", action_show_help_overlay, NULL, NULL, NULL }, { "show-help-overlay", action_show_help_overlay, NULL, NULL, NULL },
}; };
...@@ -867,10 +808,6 @@ const GOptionEntry options[] = { ...@@ -867,10 +808,6 @@ const GOptionEntry options[] = {
N_("Always open a new window for browsing specified URIs"), NULL }, N_("Always open a new window for browsing specified URIs"), NULL },
{ "no-default-window", 'n', 0, G_OPTION_ARG_NONE, NULL, { "no-default-window", 'n', 0, G_OPTION_ARG_NONE, NULL,
N_("Only create windows for explicitly specified URIs."), NULL }, N_("Only create windows for explicitly specified URIs."), NULL },
{ "no-desktop", '\0', 0, G_OPTION_ARG_NONE, NULL,
N_("Never manage the desktop (ignore the GSettings preference)."), NULL },
{ "force-desktop", '\0', 0, G_OPTION_ARG_NONE, NULL,
N_("Always manage the desktop (ignore the GSettings preference)."), NULL },
{ "quit", 'q', 0, G_OPTION_ARG_NONE, NULL, { "quit", 'q', 0, G_OPTION_ARG_NONE, NULL,
N_("Quit Nautilus."), NULL }, N_("Quit Nautilus."), NULL },
{ "select", 's', 0, G_OPTION_ARG_NONE, NULL, { "select", 's', 0, G_OPTION_ARG_NONE, NULL,
...@@ -988,30 +925,6 @@ nautilus_application_command_line (GApplication *application, ...@@ -988,30 +925,6 @@ nautilus_application_command_line (GApplication *application,
goto out; goto out;
} }
if (g_variant_dict_contains (options, "force-desktop")) {
DEBUG ("Forcing desktop, as requested");
priv->desktop_override = TRUE;
g_action_group_activate_action (G_ACTION_GROUP (application),
"open-desktop", NULL);
} else if (g_variant_dict_contains (options, "no-desktop")) {
if (g_application_get_is_remote (application)) {
DEBUG ("Not primary instance. Ignoring --no-desktop.");
} else {
DEBUG ("Forcing desktop off, as requested");
priv->desktop_override = TRUE;
g_action_group_activate_action (G_ACTION_GROUP (application),
"close-desktop", NULL);
}
}
if (g_variant_dict_contains (options, "no-default-window")) {
/* Do nothing. If icons on desktop are enabled, it will create
* the desktop window which will hold the application. If not,
* it will just exit. */
retval = EXIT_SUCCESS;
goto out;
}
retval = nautilus_application_handle_file_args (self, options); retval = nautilus_application_handle_file_args (self, options);
out: out:
...@@ -1035,58 +948,6 @@ nautilus_application_init (NautilusApplication *self) ...@@ -1035,58 +948,6 @@ nautilus_application_init (NautilusApplication *self)
g_application_add_main_option_entries (G_APPLICATION (self), options); g_application_add_main_option_entries (G_APPLICATION (self), options);
} }
static void
nautilus_application_set_desktop_visible (NautilusApplication *self,
gboolean visible)
{
const gchar *action_name;
action_name = visible ? "open-desktop" : "close-desktop";
g_action_group_activate_action (G_ACTION_GROUP (self),
action_name, NULL);
}
static void
update_desktop_from_gsettings (NautilusApplication *self)
{
NautilusApplicationPrivate *priv;
GdkDisplay *display;
gboolean visible;
priv = nautilus_application_get_instance_private (self);
/* desktop GSetting was overridden - don't do anything */
if (priv->desktop_override) {
return;
}
#ifdef GDK_WINDOWING_X11
display = gdk_display_get_default ();
visible = g_settings_get_boolean (gnome_background_preferences,
NAUTILUS_PREFERENCES_SHOW_DESKTOP);
if (!GDK_IS_X11_DISPLAY (display)) {
if (visible)
g_warning ("Desktop icons only supported on X11. Desktop not created");
return;
}
nautilus_application_set_desktop_visible (self, visible);
return;
#endif
g_warning ("Desktop icons only supported on X11. Desktop not created");
}
static void
init_desktop (NautilusApplication *self)
{
g_signal_connect_swapped (gnome_background_preferences, "changed::" NAUTILUS_PREFERENCES_SHOW_DESKTOP,
G_CALLBACK (update_desktop_from_gsettings),
self);
update_desktop_from_gsettings (self);
}
static void static void
theme_changed (GtkSettings *settings) theme_changed (GtkSettings *settings)
{ {
...@@ -1250,7 +1111,6 @@ nautilus_application_startup_common (NautilusApplication *self) ...@@ -1250,7 +1111,6 @@ nautilus_application_startup_common (NautilusApplication *self)
check_required_directories (self); check_required_directories (self);
nautilus_init_application_actions (self); nautilus_init_application_actions (self);
init_desktop (self);
nautilus_profile_end (NULL); nautilus_profile_end (NULL);
......
/* nautilus-desktop-application.c
*
* Copyright (C) 2016 Carlos Soriano <csoriano@gnome.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include "nautilus-desktop-application.h"
#include "nautilus-desktop-window.h"
#include <libnautilus-private/nautilus-global-preferences.h>
#include <eel/eel.h>
#include <gdk/gdkx.h>
struct _NautilusDesktopApplication
{
NautilusApplication parent_instance;
};
G_DEFINE_TYPE (NautilusDesktopApplication, nautilus_desktop_application, NAUTILUS_TYPE_APPLICATION)
static void
open_location_full (NautilusApplication *self,
GFile *location,
NautilusWindowOpenFlags flags,
GList *selection,
NautilusWindow *target_window,
NautilusWindowSlot *target_slot)
{
gchar *uri;
uri = g_file_get_uri (location);
if (eel_uri_is_desktop (uri) && target_window &&
NAUTILUS_IS_DESKTOP_WINDOW (target_window))
{
nautilus_window_open_location_full (target_window, location, flags, selection, NULL);
}
else
{
g_warning ("other location, use dbus to communicate with nautilus. This process is only for the desktop\n");
}
g_free (uri);
}
static void
nautilus_application_set_desktop_visible (NautilusDesktopApplication *self,
gboolean visible)
{
GtkWidget *desktop_window;
if (visible)
{
nautilus_desktop_window_ensure ();
}
else
{
desktop_window = nautilus_desktop_window_get ();
if (desktop_window != NULL)
{
gtk_widget_destroy (desktop_window);
}
}
}
static void
update_desktop_from_gsettings (NautilusDesktopApplication *self)
{
GdkDisplay *display;
gboolean visible;
#ifdef GDK_WINDOWING_X11
display = gdk_display_get_default ();
visible = g_settings_get_boolean (gnome_background_preferences,
NAUTILUS_PREFERENCES_SHOW_DESKTOP);
if (!GDK_IS_X11_DISPLAY (display))
{
if (visible)
{
g_warning ("Desktop icons only supported on X11. Desktop not created");
}
return;
}
nautilus_application_set_desktop_visible (self, visible);
return;
#endif
g_warning ("Desktop icons only supported on X11. Desktop not created");
}
static void
init_desktop (NautilusDesktopApplication *self)
{
g_signal_connect_swapped (gnome_background_preferences, "changed::" NAUTILUS_PREFERENCES_SHOW_DESKTOP,
G_CALLBACK (update_desktop_from_gsettings),
self);
update_desktop_from_gsettings (self);
}
static void
nautilus_desktop_application_activate (GApplication *app)
{
/* Do nothing */
}
static void
nautilus_desktop_application_startup (GApplication *app)
{
NautilusDesktopApplication *self = NAUTILUS_DESKTOP_APPLICATION (app);
nautilus_application_startup_common (NAUTILUS_APPLICATION (app));
init_desktop (self);
}
static void
nautilus_desktop_application_class_init (NautilusDesktopApplicationClass *klass)
{
GApplicationClass *application_class = G_APPLICATION_CLASS (klass);
NautilusApplicationClass *parent_class = NAUTILUS_APPLICATION_CLASS (klass);
parent_class->open_location_full = open_location_full;
application_class->startup = nautilus_desktop_application_startup;
application_class->activate = nautilus_desktop_application_activate;
}
static void
nautilus_desktop_application_init (NautilusDesktopApplication *self)
{
}
NautilusDesktopApplication *
nautilus_desktop_application_new (void)
{
return g_object_new (NAUTILUS_TYPE_DESKTOP_APPLICATION,
"application-id", "org.gnome.NautilusDesktop",
NULL);
}
/* nautilus-desktop-application.h
*
* Copyright (C) 2016 Carlos Soriano <csoriano@gnome.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef NAUTILUS_DESKTOP_APPLICATION_H
#define NAUTILUS_DESKTOP_APPLICATION_H
#include <glib.h>
#include "nautilus-application.h"
G_BEGIN_DECLS
#define NAUTILUS_TYPE_DESKTOP_APPLICATION (nautilus_desktop_application_get_type())
G_DECLARE_FINAL_TYPE (NautilusDesktopApplication, nautilus_desktop_application, NAUTILUS, DESKTOP_APPLICATION, NautilusApplication)
NautilusDesktopApplication *nautilus_desktop_application_new (void);
G_END_DECLS
#endif /* NAUTILUS_DESKTOP_APPLICATION_H */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment