diff options
author | Alexander Larsson <alexl@redhat.com> | 2005-02-14 10:59:23 +0000 |
---|---|---|
committer | Alexander Larsson <alexl@src.gnome.org> | 2005-02-14 10:59:23 +0000 |
commit | 00858aa133533269707d3e165ff34652b6d29c9c (patch) | |
tree | 6914a5a381bdd29f16f848f8d7f2ffd6916d335a /src | |
parent | 50d42be08e647e0b63a5492e54d3fcf7a97d7a6f (diff) | |
download | nautilus-00858aa133533269707d3e165ff34652b6d29c9c.tar.gz |
Enable startup notification.
2005-02-14 Alexander Larsson <alexl@redhat.com>
* data/applications.desktop.in:
* data/favorites.desktop.in:
* src/network-scheme.desktop.in:
* nautilus-computer.desktop.in:
* nautilus-folder-handler.desktop.in:
* nautilus-home.desktop.in:
* nautilus.desktop.in:
Enable startup notification.
* src/nautilus-application.c:
* src/nautilus-application.h:
* src/nautilus-bookmarks-window.c:
* src/nautilus-connect-server-dialog-nonmain.c:
* src/nautilus-location-bar.c:
* src/nautilus-main.c:
* src/nautilus-navigation-window-menus.c:
* src/nautilus-shell-interface.idl:
* src/nautilus-shell.c:
* src/nautilus-window-manage-views.c:
* src/nautilus-window-private.h:
* src/nautilus-window.c:
Handle startup notification across corba activation.
Patch from Elijah Newren <newren@gmail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/nautilus-application.c | 146 | ||||
-rw-r--r-- | src/nautilus-application.h | 4 | ||||
-rw-r--r-- | src/nautilus-bookmarks-window.c | 1 | ||||
-rw-r--r-- | src/nautilus-connect-server-dialog-nonmain.c | 2 | ||||
-rw-r--r-- | src/nautilus-location-bar.c | 2 | ||||
-rw-r--r-- | src/nautilus-main.c | 14 | ||||
-rw-r--r-- | src/nautilus-navigation-window-menus.c | 1 | ||||
-rw-r--r-- | src/nautilus-shell-interface.idl | 4 | ||||
-rw-r--r-- | src/nautilus-shell.c | 16 | ||||
-rw-r--r-- | src/nautilus-window-manage-views.c | 4 | ||||
-rw-r--r-- | src/nautilus-window-private.h | 3 | ||||
-rw-r--r-- | src/nautilus-window.c | 6 | ||||
-rw-r--r-- | src/network-scheme.desktop.in | 1 |
13 files changed, 190 insertions, 14 deletions
diff --git a/src/nautilus-application.c b/src/nautilus-application.c index 5358b7422..1ca351816 100644 --- a/src/nautilus-application.c +++ b/src/nautilus-application.c @@ -83,6 +83,8 @@ #include <libnautilus-private/nautilus-desktop-link-monitor.h> #include <libnautilus-private/nautilus-directory-private.h> #include <bonobo-activation/bonobo-activation.h> +#define SN_API_NOT_YET_FROZEN Yes_i_know_DO_IT +#include <libsn/sn-launchee.h> /* Needed for the is_kdesktop_present check */ #include <gdk/gdkx.h> @@ -452,6 +454,7 @@ nautilus_application_startup (NautilusApplication *application, gboolean no_desktop, gboolean do_first_time_druid_check, gboolean browser_window, + const char *startup_id, const char *geometry, const char *urls[]) { @@ -461,6 +464,7 @@ nautilus_application_startup (NautilusApplication *application, const char *message, *detailed_message; GtkDialog *dialog; Nautilus_URIList *url_list; + const CORBA_char *corba_startup_id; const CORBA_char *corba_geometry; int num_failures; @@ -610,15 +614,16 @@ nautilus_application_startup (NautilusApplication *application, /* CORBA C mapping doesn't allow NULL to be passed for string parameters */ - corba_geometry = (geometry != NULL) ? geometry : ""; + corba_geometry = (geometry != NULL) ? geometry : ""; + corba_startup_id = (startup_id != NULL) ? startup_id : ""; /* Create the other windows. */ if (urls != NULL) { url_list = nautilus_make_uri_list_from_shell_strv (urls); - Nautilus_Shell_open_windows (shell, url_list, corba_geometry, browser_window, &ev); + Nautilus_Shell_open_windows (shell, url_list, corba_startup_id, corba_geometry, browser_window, &ev); CORBA_free (url_list); } else if (!no_default_window) { - Nautilus_Shell_open_default_window (shell, corba_geometry, browser_window, &ev); + Nautilus_Shell_open_default_window (shell, corba_startup_id, corba_geometry, browser_window, &ev); } /* Add ourselves to the session */ @@ -926,6 +931,7 @@ nautilus_window_delete_event_callback (GtkWidget *widget, static NautilusWindow * create_window (NautilusApplication *application, GType window_type, + const char *startup_id, GdkScreen *screen) { NautilusWindow *window; @@ -939,6 +945,10 @@ create_window (NautilusApplication *application, /* Must be called after construction finished */ nautilus_window_constructed (window); + if (startup_id != NULL) { + window->details->startup_id = g_strdup (startup_id); + } + g_signal_connect_data (window, "delete_event", G_CALLBACK (nautilus_window_delete_event_callback), NULL, NULL, G_CONNECT_AFTER); @@ -966,21 +976,135 @@ spatial_window_destroyed_callback (void *user_data, GObject *window) NautilusWindow * nautilus_application_present_spatial_window (NautilusApplication *application, NautilusWindow *requesting_window, + const char *startup_id, const char *location, GdkScreen *screen) { return nautilus_application_present_spatial_window_with_selection (application, requesting_window, + startup_id, location, NULL, screen); } +static void +sn_error_trap_push (SnDisplay *display, + Display *xdisplay) +{ + gdk_error_trap_push (); +} + +static void +sn_error_trap_pop (SnDisplay *display, + Display *xdisplay) +{ + gdk_error_trap_pop (); +} + +static gboolean +id_string_has_timestamp (const char *startup_id_string) +{ + char * time_str; + + time_str = g_strrstr (startup_id_string, "_TIME"); + + return time_str != NULL; +} + +static guint32 +get_timestamp_from_id_string (const char *startup_id_string) +{ + char *time_str; + gchar *end; + gulong retval; + + retval = 0; + time_str = g_strrstr (startup_id_string, "_TIME"); + g_assert (time_str != NULL); + + errno = 0; + + /* Skip past the "_TIME" part */ + time_str += 5; + + retval = strtoul (time_str, &end, 0); + if (end == time_str || errno != 0) { + g_warning ("startup_id is messed up\n"); + } + + return retval; +} + +static void +end_startup_notification (GtkWidget *widget, + const char *startup_id_to_end, + const char *startup_id_with_timestamp) +{ + SnDisplay *sn_display; + SnLauncheeContext *context; + GdkDisplay *display; + GdkScreen *screen; + + g_return_if_fail (startup_id_to_end != NULL); + + if (!GTK_WIDGET_REALIZED (widget)) { + gtk_widget_realize (widget); + } + + context = NULL; + sn_display = NULL; + + /* Set up window for launch notification */ + /* FIXME In principle all transient children of this + * window should get the same startup_id + */ + + screen = gtk_widget_get_screen (widget); + display = gdk_screen_get_display (screen); + + sn_display = sn_display_new (gdk_x11_display_get_xdisplay (display), + sn_error_trap_push, + sn_error_trap_pop); + + context = sn_launchee_context_new (sn_display, + gdk_screen_get_number (screen), + startup_id_to_end); + + if (startup_id_with_timestamp == NULL) { + sn_launchee_context_setup_window (context, + GDK_WINDOW_XWINDOW (widget->window)); + startup_id_with_timestamp = startup_id_to_end; + } + + /* Now, set the _NET_WM_USER_TIME for the new window to the timestamp + * that caused the window to be launched. + */ + if (id_string_has_timestamp (startup_id_with_timestamp)) { + gulong startup_id_timestamp; + startup_id_timestamp = get_timestamp_from_id_string (startup_id_with_timestamp); + gdk_x11_window_set_user_time (widget->window, startup_id_timestamp); + } else { + /* Comment this out for now, as it warns way to often. + * like when launching nautilus from the terminal. + + g_warning ("Launched by a non-compliant or obsolete startup " + "notification launcher. Focus-stealing-prevention " + "may fail.\n"); + */ + } + + sn_launchee_context_complete (context); + sn_launchee_context_unref (context); + sn_display_unref (sn_display); +} + NautilusWindow * nautilus_application_present_spatial_window_with_selection (NautilusApplication *application, NautilusWindow *requesting_window, + const char *startup_id, const char *location, - GList *new_selection, + GList *new_selection, GdkScreen *screen) { NautilusWindow *window; @@ -1001,6 +1125,9 @@ nautilus_application_present_spatial_window_with_selection (NautilusApplication } if (eel_uris_match (existing_location, location)) { + end_startup_notification (GTK_WIDGET (existing_window), + existing_window->details->startup_id, + startup_id); gtk_window_present (GTK_WINDOW (existing_window)); if (new_selection) { nautilus_view_set_selection (existing_window->content_view, new_selection); @@ -1009,7 +1136,10 @@ nautilus_application_present_spatial_window_with_selection (NautilusApplication } } - window = create_window (application, NAUTILUS_TYPE_SPATIAL_WINDOW, screen); + window = create_window (application, NAUTILUS_TYPE_SPATIAL_WINDOW, startup_id, screen); + end_startup_notification (GTK_WIDGET (window), + startup_id, + NULL); if (requesting_window) { /* Center the window over the requesting window by default */ int orig_x, orig_y, orig_width, orig_height; @@ -1044,13 +1174,17 @@ nautilus_application_present_spatial_window_with_selection (NautilusApplication NautilusWindow * nautilus_application_create_navigation_window (NautilusApplication *application, + const char *startup_id, GdkScreen *screen) { NautilusWindow *window; g_return_val_if_fail (NAUTILUS_IS_APPLICATION (application), NULL); - window = create_window (application, NAUTILUS_TYPE_NAVIGATION_WINDOW, screen); + window = create_window (application, NAUTILUS_TYPE_NAVIGATION_WINDOW, startup_id, screen); + end_startup_notification (GTK_WIDGET (window), + startup_id, + NULL); return window; } diff --git a/src/nautilus-application.h b/src/nautilus-application.h index 9227723cf..419b842f9 100644 --- a/src/nautilus-application.h +++ b/src/nautilus-application.h @@ -67,6 +67,7 @@ void nautilus_application_startup (NautilusApplication gboolean no_desktop, gboolean do_first_time_druid_check, gboolean browser_window, + const char *startup_id, const char *default_geometry, const char *urls[]); GList * nautilus_application_get_window_list (void); @@ -74,15 +75,18 @@ GList * nautilus_application_get_spatial_window_list (void); NautilusWindow * nautilus_application_present_spatial_window (NautilusApplication *application, NautilusWindow *requesting_window, + const char *startup_id, const char *location, GdkScreen *screen); NautilusWindow * nautilus_application_present_spatial_window_with_selection (NautilusApplication *application, NautilusWindow *requesting_window, + const char *startup_id, const char *location, GList *new_selection, GdkScreen *screen); NautilusWindow * nautilus_application_create_navigation_window (NautilusApplication *application, + const char *startup_id, GdkScreen *screen); void nautilus_application_close_all_navigation_windows (void); diff --git a/src/nautilus-bookmarks-window.c b/src/nautilus-bookmarks-window.c index 983ccd59c..04742c71e 100644 --- a/src/nautilus-bookmarks-window.c +++ b/src/nautilus-bookmarks-window.c @@ -555,6 +555,7 @@ get_bookmark_nautilus_navigation_window_new (GdkScreen *screen) application = nautilus_application_new (); window = nautilus_application_create_navigation_window (application, + NULL, screen); return window; diff --git a/src/nautilus-connect-server-dialog-nonmain.c b/src/nautilus-connect-server-dialog-nonmain.c index 0481afb95..408eb8838 100644 --- a/src/nautilus-connect-server-dialog-nonmain.c +++ b/src/nautilus-connect-server-dialog-nonmain.c @@ -39,11 +39,13 @@ nautilus_connect_server_dialog_present_uri (NautilusApplication *application, if (eel_preferences_get_boolean (NAUTILUS_PREFERENCES_ALWAYS_USE_BROWSER)) { window = nautilus_application_create_navigation_window (application, + NULL, gtk_widget_get_screen (widget)); nautilus_window_go_to (window, uri); } else { nautilus_application_present_spatial_window (application, NULL, + NULL, uri, gtk_widget_get_screen (widget)); } diff --git a/src/nautilus-location-bar.c b/src/nautilus-location-bar.c index 6140b2d0f..cbe7e1eb3 100644 --- a/src/nautilus-location-bar.c +++ b/src/nautilus-location-bar.c @@ -189,7 +189,7 @@ drag_data_received_callback (GtkWidget *widget, screen = gtk_window_get_screen (GTK_WINDOW (window)); for (node = names->next; node != NULL; node = node->next) { - new_window = nautilus_application_create_navigation_window (application, screen); + new_window = nautilus_application_create_navigation_window (application, NULL, screen); nautilus_window_go_to (new_window, node->data); } } diff --git a/src/nautilus-main.c b/src/nautilus-main.c index 5d0f52faf..9417eff89 100644 --- a/src/nautilus-main.c +++ b/src/nautilus-main.c @@ -196,6 +196,8 @@ main (int argc, char *argv[]) gboolean no_default_window; gboolean browser_window; gboolean no_desktop; + const char *startup_id; + char *startup_id_copy; char *geometry; gboolean perform_self_check; poptContext popt_context; @@ -246,6 +248,17 @@ main (int argc, char *argv[]) bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); + startup_id = g_getenv ("DESKTOP_STARTUP_ID"); + startup_id_copy = NULL; + if (startup_id != NULL && *startup_id != '\0') { + /* Clear the DESKTOP_STARTUP_ID, but make sure to copy it first */ + startup_id_copy = g_strdup (startup_id); + putenv ("DESKTOP_STARTUP_ID="); + } + + /* we'll do it ourselves due to complicated factory setup */ + gtk_window_set_auto_startup_notification (FALSE); + /* Get parameters. */ geometry = NULL; kill_shell = FALSE; @@ -349,6 +362,7 @@ main (int argc, char *argv[]) kill_shell, restart_shell, no_default_window, no_desktop, !(kill_shell || restart_shell), browser_window, + startup_id_copy, geometry, args); if (is_event_loop_needed ()) { diff --git a/src/nautilus-navigation-window-menus.c b/src/nautilus-navigation-window-menus.c index ebc9ebd13..524fb382b 100644 --- a/src/nautilus-navigation-window-menus.c +++ b/src/nautilus-navigation-window-menus.c @@ -520,6 +520,7 @@ action_new_window_callback (GtkAction *action, current_window = NAUTILUS_WINDOW (user_data); new_window = nautilus_application_create_navigation_window ( current_window->application, + NULL, gtk_window_get_screen (GTK_WINDOW (current_window))); nautilus_window_go_home (new_window); } diff --git a/src/nautilus-shell-interface.idl b/src/nautilus-shell-interface.idl index 3b4649a92..bbb999360 100644 --- a/src/nautilus-shell-interface.idl +++ b/src/nautilus-shell-interface.idl @@ -10,8 +10,8 @@ module Nautilus { typedef sequence<URI> URIList; interface Shell : ::Bonobo::Unknown { - void open_windows (in URIList uris, in string geometry, in boolean browser_window); - void open_default_window (in string geometry, in boolean browser_window); + void open_windows (in URIList uris, in string startup_id, in string geometry, in boolean browser_window); + void open_default_window (in string startup_id, in string geometry, in boolean browser_window); void start_desktop (); void stop_desktop (); void quit (); diff --git a/src/nautilus-shell.c b/src/nautilus-shell.c index 1967c7ff7..6e5c6124d 100644 --- a/src/nautilus-shell.c +++ b/src/nautilus-shell.c @@ -63,10 +63,12 @@ struct NautilusShellDetails { static void finalize (GObject *shell); static void corba_open_windows (PortableServer_Servant servant, const Nautilus_URIList *list, + const CORBA_char *startup_id, const CORBA_char *geometry, CORBA_boolean browser_window, CORBA_Environment *ev); static void corba_open_default_window (PortableServer_Servant servant, + const CORBA_char *startup_id, const CORBA_char *geometry, CORBA_boolean browser_window, CORBA_Environment *ev); @@ -125,8 +127,8 @@ nautilus_shell_new (NautilusApplication *application) } static void -open_window (NautilusShell *shell, const char *uri, const char *geometry, - gboolean browser_window) +open_window (NautilusShell *shell, const char *uri, const char *startup_id, + const char *geometry, gboolean browser_window) { char *home_uri; NautilusWindow *window; @@ -134,6 +136,7 @@ open_window (NautilusShell *shell, const char *uri, const char *geometry, if (browser_window || eel_preferences_get_boolean (NAUTILUS_PREFERENCES_ALWAYS_USE_BROWSER)) { window = nautilus_application_create_navigation_window (shell->details->application, + startup_id, gdk_screen_get_default ()); if (uri == NULL) { nautilus_window_go_home (window); @@ -149,6 +152,7 @@ open_window (NautilusShell *shell, const char *uri, const char *geometry, window = nautilus_application_present_spatial_window (shell->details->application, NULL, + startup_id, uri, gdk_screen_get_default ()); g_free (home_uri); @@ -166,6 +170,7 @@ open_window (NautilusShell *shell, const char *uri, const char *geometry, static void corba_open_windows (PortableServer_Servant servant, const Nautilus_URIList *list, + const CORBA_char *startup_id, const CORBA_char *geometry, CORBA_boolean browser_window, CORBA_Environment *ev) @@ -178,12 +183,13 @@ corba_open_windows (PortableServer_Servant servant, /* Open windows at each requested location. */ for (i = 0; i < list->_length; i++) { g_assert (list->_buffer[i] != NULL); - open_window (shell, list->_buffer[i], geometry, browser_window); + open_window (shell, list->_buffer[i], startup_id, geometry, browser_window); } } static void corba_open_default_window (PortableServer_Servant servant, + const CORBA_char *startup_id, const CORBA_char *geometry, CORBA_boolean browser_window, CORBA_Environment *ev) @@ -194,7 +200,7 @@ corba_open_default_window (PortableServer_Servant servant, if (!restore_window_states (shell)) { /* Open a window pointing at the default location. */ - open_window (shell, NULL, geometry, browser_window); + open_window (shell, NULL, startup_id, geometry, browser_window); } } @@ -345,10 +351,12 @@ restore_one_window_callback (const char *attributes, if (eel_strlen (location) > 0) { window = nautilus_application_present_spatial_window (shell->details->application, NULL, + NULL, /* FIXME: Need startup_id? */ location, screen); } else { window = nautilus_application_create_navigation_window (shell->details->application, + NULL, /* FIXME: Need startup_id? */ screen); nautilus_window_go_home (window); } diff --git a/src/nautilus-window-manage-views.c b/src/nautilus-window-manage-views.c index a8419e34b..3854adc95 100644 --- a/src/nautilus-window-manage-views.c +++ b/src/nautilus-window-manage-views.c @@ -451,6 +451,7 @@ nautilus_window_open_location_full (NautilusWindow *window, if (!NAUTILUS_SPATIAL_WINDOW (window)->affect_spatial_window_on_next_location_change) { target_window = nautilus_application_create_navigation_window (window->application, + NULL, gtk_window_get_screen (GTK_WINDOW (window))); } else { NAUTILUS_SPATIAL_WINDOW (window)->affect_spatial_window_on_next_location_change = FALSE; @@ -461,6 +462,7 @@ nautilus_window_open_location_full (NautilusWindow *window, target_window = nautilus_application_present_spatial_window_with_selection ( window->application, window, + NULL, location, new_selection, gtk_window_get_screen (GTK_WINDOW (window))); @@ -477,12 +479,14 @@ nautilus_window_open_location_full (NautilusWindow *window, target_window = nautilus_application_present_spatial_window ( window->application, window, + NULL, location, gtk_window_get_screen (GTK_WINDOW (window))); break; case NAUTILUS_WINDOW_OPEN_IN_NAVIGATION : target_window = nautilus_application_create_navigation_window (window->application, + NULL, gtk_window_get_screen (GTK_WINDOW (window))); break; default : diff --git a/src/nautilus-window-private.h b/src/nautilus-window-private.h index 8ef9acef3..d24e4b86c 100644 --- a/src/nautilus-window-private.h +++ b/src/nautilus-window-private.h @@ -56,6 +56,9 @@ struct NautilusWindowDetails GtkUIManager *ui_manager; GtkActionGroup *main_action_group; /* owned by ui_manager */ guint help_message_cid; + + /* Startup ID; for startup notification shutoff */ + char *startup_id; /* Menus. */ guint extensions_menu_merge_id; diff --git a/src/nautilus-window.c b/src/nautilus-window.c index 6bae6993e..9e254c48e 100644 --- a/src/nautilus-window.c +++ b/src/nautilus-window.c @@ -143,6 +143,8 @@ nautilus_window_init (NautilusWindow *window) window->details->show_hidden_files_mode = NAUTILUS_WINDOW_SHOW_HIDDEN_FILES_DEFAULT; + window->details->startup_id = NULL; + /* Set initial window title */ gtk_window_set_title (GTK_WINDOW (window), _("Nautilus")); @@ -463,7 +465,7 @@ nautilus_window_constructed (NautilusWindow *window) static void nautilus_window_set_property (GObject *object, guint arg_id, - const GValue *value, + const GValue *value, GParamSpec *pspec) { NautilusWindow *window; @@ -551,6 +553,8 @@ nautilus_window_finalize (GObject *object) g_source_remove (window->details->location_change_at_idle_id); } + g_free (window->details->startup_id); + g_free (window->details->title); g_free (window->details); diff --git a/src/network-scheme.desktop.in b/src/network-scheme.desktop.in index 07b5ee0ea..966c9d589 100644 --- a/src/network-scheme.desktop.in +++ b/src/network-scheme.desktop.in @@ -5,6 +5,7 @@ _Comment=View your network servers in the Nautilus file manager TryExec=nautilus Exec=nautilus network: Terminal=false +StartupNotify=true Type=Application Icon=gnome-fs-network Categories=Application;Core; |