@@ -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 */
@@ -552,6 +578,7 @@ nemo_main_application_open (GApplication *app,
552578 gboolean open_in_tabs = FALSE;
553579 gchar * geometry = NULL ;
554580 gboolean open_in_existing_window = strcmp (options , "EXISTING_WINDOW" ) == 0 ;
581+ gboolean default_no_args = FALSE;
555582 const char splitter = '=' ;
556583
557584 g_debug ("Open called on the GApplication instance; %d files" , n_files );
@@ -560,7 +587,12 @@ nemo_main_application_open (GApplication *app,
560587 /* Check if local command line passed --geometry or --tabs */
561588 if (strlen (options ) > 0 ) {
562589 gchar * * split_options = g_strsplit (options , & splitter , 2 );
563- if (strcmp (split_options [0 ], "NULL" ) != 0 ) {
590+ if (g_str_has_prefix (split_options [0 ], "DEFAULT" )) {
591+ default_no_args = TRUE;
592+ if (g_str_has_prefix (split_options [0 ], "DEFAULT+" )) {
593+ geometry = g_strdup (split_options [0 ] + strlen ("DEFAULT+" ));
594+ }
595+ } else if (strcmp (split_options [0 ], "NULL" ) != 0 ) {
564596 geometry = g_strdup (split_options [0 ]);
565597 }
566598 sscanf (split_options [1 ], "%d" , & open_in_tabs );
@@ -575,7 +607,13 @@ nemo_main_application_open (GApplication *app,
575607 geometry ? geometry : "none" ,
576608 open_in_existing_window ? "yes" : "no" );
577609
578- open_windows (self , files , n_files , gdk_screen_get_default (), geometry , open_in_tabs , open_in_existing_window );
610+ if (default_no_args ) {
611+ /* Treat this as a no-arg launch; open_windows() will attempt session restore
612+ * and fall back to Home if restore isn't possible. */
613+ open_windows (self , NULL , 0 , gdk_screen_get_default (), geometry , open_in_tabs , open_in_existing_window );
614+ } else {
615+ open_windows (self , files , n_files , gdk_screen_get_default (), geometry , open_in_tabs , open_in_existing_window );
616+ }
579617
580618 g_clear_pointer (& geometry , g_free );
581619}
@@ -820,9 +858,11 @@ nemo_main_application_local_command_line (GApplication *application,
820858
821859 GFile * * files ;
822860 gint idx , len ;
861+ gboolean used_default_location ;
823862
824863 len = 0 ;
825864 files = NULL ;
865+ used_default_location = FALSE;
826866
827867 /* Convert args to GFiles */
828868 if (remaining != NULL ) {
@@ -844,11 +884,15 @@ nemo_main_application_local_command_line (GApplication *application,
844884 }
845885
846886 if (files == NULL && !no_default_window ) {
887+ /* Original behavior: default to Home when no URIs are provided. */
847888 files = g_malloc0 (2 * sizeof (GFile * ));
848889 len = 1 ;
849890
850891 files [0 ] = g_file_new_for_path (g_get_home_dir ());
851892 files [1 ] = NULL ;
893+
894+ /* Mark that this was a no-arg launch, not an explicit URI. */
895+ used_default_location = TRUE;
852896 }
853897 /* --select: open the parent dir and highlight the requested file */
854898 if (select_uri != NULL ) {
@@ -868,27 +912,40 @@ nemo_main_application_local_command_line (GApplication *application,
868912 goto out_free_files ;
869913 }
870914
871- /* Invoke "Open" to open in existing window or create new windows */
915+ /* Invoke "Open" to open in existing window or create new windows.
916+ */
872917 if (len > 0 ) {
873918 gchar * concatOptions = g_malloc0 (64 );
874919 if (open_in_existing_window ) {
875920 g_stpcpy (concatOptions , "EXISTING_WINDOW" );
876921 } else {
877922 if (self -> priv -> geometry == NULL ) {
878- g_snprintf (concatOptions , 64 , "NULL=%d" , open_in_tabs );
923+ /* If Home was synthesized because no URIs were passed, signal that
924+ * to the primary instance so it can attempt session restore. */
925+ if (used_default_location ) {
926+ g_snprintf (concatOptions , 64 , "DEFAULT=%d" , open_in_tabs );
927+ } else {
928+ g_snprintf (concatOptions , 64 , "NULL=%d" , open_in_tabs );
929+ }
879930 } else {
880- g_snprintf (concatOptions , 64 , "%s=%d" , self -> priv -> geometry , open_in_tabs );
931+ if (used_default_location ) {
932+ g_snprintf (concatOptions , 64 , "DEFAULT+%s=%d" , self -> priv -> geometry , open_in_tabs );
933+ } else {
934+ g_snprintf (concatOptions , 64 , "%s=%d" , self -> priv -> geometry , open_in_tabs );
935+ }
881936 }
882937 }
883938 g_application_open (application , files , len , concatOptions );
884939 g_free (concatOptions );
885940 }
886941
887- out_free_files :
888- for (idx = 0 ; idx < len ; idx ++ ) {
889- g_object_unref (files [idx ]);
942+ out_free_files :
943+ if (files != NULL ) {
944+ for (idx = 0 ; idx < len ; idx ++ ) {
945+ g_object_unref (files [idx ]);
946+ }
947+ g_free (files );
890948 }
891- g_free (files );
892949
893950 out :
894951 g_option_context_free (context );
0 commit comments