@@ -483,8 +483,34 @@ open_windows (NemoMainApplication *application,
483483 gint i ;
484484
485485 if (files == NULL || files [0 ] == NULL ) {
486- /* Open a window pointing at the default location. */
487- open_window (application , NULL , screen , geometry );
486+ /* No explicit locations requested: try restoring the last session. */
487+ NemoWindow * window ;
488+ gboolean have_geometry ;
489+ gboolean do_restore ;
490+
491+ window = nemo_main_application_create_window (NEMO_APPLICATION (application ), screen );
492+
493+ have_geometry = geometry != NULL && strcmp (geometry , "" ) != 0 ;
494+ if (have_geometry && !gtk_widget_get_visible (GTK_WIDGET (window ))) {
495+ /* never maximize windows opened from shell if a
496+ * custom geometry has been requested.
497+ */
498+ gtk_window_unmaximize (GTK_WINDOW (window ));
499+ eel_gtk_window_set_initial_geometry_from_string (GTK_WINDOW (window ),
500+ geometry ,
501+ APPLICATION_WINDOW_MIN_WIDTH ,
502+ APPLICATION_WINDOW_MIN_HEIGHT ,
503+ FALSE);
504+ }
505+
506+ do_restore = g_settings_get_boolean (nemo_preferences , NEMO_PREFERENCES_RESTORE_TABS_ON_STARTUP );
507+
508+ if (!do_restore || !nemo_window_restore_saved_tabs (window )) {
509+ /* Fall back to a safe default location */
510+ GFile * home = g_file_new_for_path (g_get_home_dir ());
511+ nemo_window_go_to (window , home );
512+ g_object_unref (home );
513+ }
488514 } else {
489515 if (open_in_existing_window ) {
490516 /* Open one tab at each requested location in an existing window */
@@ -542,6 +568,7 @@ nemo_main_application_open (GApplication *app,
542568 gboolean open_in_tabs = FALSE;
543569 gchar * geometry = NULL ;
544570 gboolean open_in_existing_window = strcmp (options , "EXISTING_WINDOW" ) == 0 ;
571+ gboolean default_no_args = FALSE;
545572 const char splitter = '=' ;
546573
547574 g_debug ("Open called on the GApplication instance; %d files" , n_files );
@@ -550,7 +577,12 @@ nemo_main_application_open (GApplication *app,
550577 /* Check if local command line passed --geometry or --tabs */
551578 if (strlen (options ) > 0 ) {
552579 gchar * * split_options = g_strsplit (options , & splitter , 2 );
553- if (strcmp (split_options [0 ], "NULL" ) != 0 ) {
580+ if (g_str_has_prefix (split_options [0 ], "DEFAULT" )) {
581+ default_no_args = TRUE;
582+ if (g_str_has_prefix (split_options [0 ], "DEFAULT+" )) {
583+ geometry = g_strdup (split_options [0 ] + strlen ("DEFAULT+" ));
584+ }
585+ } else if (strcmp (split_options [0 ], "NULL" ) != 0 ) {
554586 geometry = g_strdup (split_options [0 ]);
555587 }
556588 sscanf (split_options [1 ], "%d" , & open_in_tabs );
@@ -565,7 +597,13 @@ nemo_main_application_open (GApplication *app,
565597 geometry ? geometry : "none" ,
566598 open_in_existing_window ? "yes" : "no" );
567599
568- open_windows (self , files , n_files , gdk_screen_get_default (), geometry , open_in_tabs , open_in_existing_window );
600+ if (default_no_args ) {
601+ /* Treat this as a no-arg launch; open_windows() will attempt session restore
602+ * and fall back to Home if restore isn't possible. */
603+ open_windows (self , NULL , 0 , gdk_screen_get_default (), geometry , open_in_tabs , open_in_existing_window );
604+ } else {
605+ open_windows (self , files , n_files , gdk_screen_get_default (), geometry , open_in_tabs , open_in_existing_window );
606+ }
569607
570608 g_clear_pointer (& geometry , g_free );
571609}
@@ -807,9 +845,11 @@ nemo_main_application_local_command_line (GApplication *application,
807845
808846 GFile * * files ;
809847 gint idx , len ;
848+ gboolean used_default_location ;
810849
811850 len = 0 ;
812851 files = NULL ;
852+ used_default_location = FALSE;
813853
814854 /* Convert args to GFiles */
815855 if (remaining != NULL ) {
@@ -831,32 +871,50 @@ nemo_main_application_local_command_line (GApplication *application,
831871 }
832872
833873 if (files == NULL && !no_default_window ) {
874+ /* Original behavior: default to Home when no URIs are provided. */
834875 files = g_malloc0 (2 * sizeof (GFile * ));
835876 len = 1 ;
836877
837878 files [0 ] = g_file_new_for_path (g_get_home_dir ());
838879 files [1 ] = NULL ;
880+
881+ /* Mark that this was a no-arg launch, not an explicit URI. */
882+ used_default_location = TRUE;
839883 }
840- /* Invoke "Open" to open in existing window or create new windows */
884+
885+ /* Invoke "Open" to open in existing window or create new windows.
886+ */
841887 if (len > 0 ) {
842888 gchar * concatOptions = g_malloc0 (64 );
843889 if (open_in_existing_window ) {
844890 g_stpcpy (concatOptions , "EXISTING_WINDOW" );
845891 } else {
846892 if (self -> priv -> geometry == NULL ) {
847- g_snprintf (concatOptions , 64 , "NULL=%d" , open_in_tabs );
893+ /* If Home was synthesized because no URIs were passed, signal that
894+ * to the primary instance so it can attempt session restore. */
895+ if (used_default_location ) {
896+ g_snprintf (concatOptions , 64 , "DEFAULT=%d" , open_in_tabs );
897+ } else {
898+ g_snprintf (concatOptions , 64 , "NULL=%d" , open_in_tabs );
899+ }
848900 } else {
849- g_snprintf (concatOptions , 64 , "%s=%d" , self -> priv -> geometry , open_in_tabs );
901+ if (used_default_location ) {
902+ g_snprintf (concatOptions , 64 , "DEFAULT+%s=%d" , self -> priv -> geometry , open_in_tabs );
903+ } else {
904+ g_snprintf (concatOptions , 64 , "%s=%d" , self -> priv -> geometry , open_in_tabs );
905+ }
850906 }
851907 }
852908 g_application_open (application , files , len , concatOptions );
853909 g_free (concatOptions );
854910 }
855911
856- for (idx = 0 ; idx < len ; idx ++ ) {
857- g_object_unref (files [idx ]);
912+ if (files != NULL ) {
913+ for (idx = 0 ; idx < len ; idx ++ ) {
914+ g_object_unref (files [idx ]);
915+ }
916+ g_free (files );
858917 }
859- g_free (files );
860918
861919 out :
862920 g_option_context_free (context );
0 commit comments