Can now remember last app run, so on return to mmenu it jumps right back there
authorskeezix <skeezix@flotsam-vm.(none)>
Wed, 9 Nov 2011 19:44:43 +0000 (14:44 -0500)
committerskeezix <skeezix@flotsam-vm.(none)>
Wed, 9 Nov 2011 19:44:43 +0000 (14:44 -0500)
--> defaults to _yes_, but used to be _no_, so people need to reset conf in the menu
or toggle it to Yes; a reflash or new users will default to yes

minimenu/mmconf.c
minimenu/mmconf.h
minimenu/mmenu.c
minimenu/mmui.c

index c038e2e..2535a06 100644 (file)
@@ -35,7 +35,7 @@ confitem_t page_general[] = {
   { "Detail panel on start?",        "Show or hide the detail panel when menu starts",          "1",                "display.show_detail_pane", ct_boolean },
   { "Sub-categories as folders?",    "If no, uses tabs instead of folders within tabs.",        "1",                "tabs.subcat_as_folders",  ct_boolean },
   { "Sub-category apps in their main cat?","If no, apps with subcategories are only in subcategories","1",          "tabs.subcat_to_parent",   ct_boolean },
   { "Detail panel on start?",        "Show or hide the detail panel when menu starts",          "1",                "display.show_detail_pane", ct_boolean },
   { "Sub-categories as folders?",    "If no, uses tabs instead of folders within tabs.",        "1",                "tabs.subcat_as_folders",  ct_boolean },
   { "Sub-category apps in their main cat?","If no, apps with subcategories are only in subcategories","1",          "tabs.subcat_to_parent",   ct_boolean },
-  { "Start with app selected",       "Whethor selection is placed by default or not",           "0",                "minimenu.start_selected", ct_boolean },
+  { "Remember selected app",         "On return to menu select previous app; default to selected", "1",             "minimenu.start_selected", ct_boolean },
   { "Auto discover pnd apps?",       "If no, turn on diectory browser to manually find apps",   "1",                "filesystem.do_pnd_disco", ct_boolean },
   // dropped option -- we now strictly enforce free desktop categories (or user defined, but no more bogus PXML categories)
   //    { "Keep bad categories in Other?", "Lazy dev! Put broken categories into Other to keep clean", "1",               "categories.good_cats_only", ct_boolean },
   { "Auto discover pnd apps?",       "If no, turn on diectory browser to manually find apps",   "1",                "filesystem.do_pnd_disco", ct_boolean },
   // dropped option -- we now strictly enforce free desktop categories (or user defined, but no more bogus PXML categories)
   //    { "Keep bad categories in Other?", "Lazy dev! Put broken categories into Other to keep clean", "1",               "categories.good_cats_only", ct_boolean },
@@ -693,6 +693,18 @@ unsigned char conf_write ( pnd_conf_handle h, char *fullpath ) {
     v = pnd_box_get_next ( v );
   } // while
 
     v = pnd_box_get_next ( v );
   } // while
 
+  // really, should write out keys that are not found in the conf items..
+  // but since g_conf is merged with other conf files, that may just
+  // make for big dumps erroneously.. hmm :/
+  char *previous_unique_id = pnd_conf_get_as_char ( g_conf, "minimenu.last_known_app_uid" );
+  char *lastcat = pnd_conf_get_as_char ( g_conf, "minimenu.last_known_catname" );
+  if ( previous_unique_id ) {
+    fprintf ( f, "%s\t%s\n", "minimenu.last_known_app_uid", previous_unique_id );
+  }
+  if ( lastcat ) {
+    fprintf ( f, "%s\t%s\n", "minimenu.last_known_catname", lastcat );
+  }
+
   fclose ( f );
 
   return ( 1 );
   fclose ( f );
 
   return ( 1 );
index 8408e2b..4f07c43 100644 (file)
@@ -41,6 +41,7 @@ unsigned int conf_determine_pagelength ( confitem_t *page );
 void conf_merge_into ( char *fullpath, pnd_conf_handle h ); // merge fullpath as a conf file into 'h'; no turning back.
 unsigned char conf_write ( pnd_conf_handle h, char *fullpath ); // emit a conf file, based on items known to conf-ui
 #define CONF_PREF_FILENAME ".mmpref.conf" // or should be .mmprefrc? tend to use '.conf' already so go with it.
 void conf_merge_into ( char *fullpath, pnd_conf_handle h ); // merge fullpath as a conf file into 'h'; no turning back.
 unsigned char conf_write ( pnd_conf_handle h, char *fullpath ); // emit a conf file, based on items known to conf-ui
 #define CONF_PREF_FILENAME ".mmpref.conf" // or should be .mmprefrc? tend to use '.conf' already so go with it.
+#define CONF_PREF_TEMPPATH "/tmp/" CONF_PREF_FILENAME
 char *conf_determine_location ( pnd_conf_handle h ); // where to stick the conf file?
 void conf_setup_missing ( pnd_conf_handle h ); // find missing keys, set them to default values
 
 char *conf_determine_location ( pnd_conf_handle h ); // where to stick the conf file?
 void conf_setup_missing ( pnd_conf_handle h ); // find missing keys, set them to default values
 
index 1c39c99..5946cc8 100644 (file)
@@ -182,7 +182,14 @@ int main ( int argc, char *argv[] ) {
   }
 
   // override mmenu conf via user preference conf
   }
 
   // override mmenu conf via user preference conf
-  conf_merge_into ( conf_determine_location ( g_conf ), g_conf );
+  // first check /tmp location in case we're storing this-session prefs; if not
+  // found, go back to normal NAND copy in homedir
+  struct stat statbuf;
+  if ( stat ( CONF_PREF_TEMPPATH, &statbuf ) == 0 ) {
+    conf_merge_into ( CONF_PREF_TEMPPATH, g_conf );
+  } else {
+    conf_merge_into ( conf_determine_location ( g_conf ), g_conf );
+  }
   conf_setup_missing ( g_conf );
 
   // desktop conf for app finding preferences
   conf_setup_missing ( g_conf );
 
   // desktop conf for app finding preferences
index d0e0ce5..e7e8fe1 100644 (file)
@@ -384,7 +384,32 @@ void ui_render ( void ) {
 #if 1
   // if no selected app yet, select the first one
   if ( ! ui_selected && pnd_conf_get_as_int_d ( g_conf, "minimenu.start_selected", 0 ) ) {
 #if 1
   // if no selected app yet, select the first one
   if ( ! ui_selected && pnd_conf_get_as_int_d ( g_conf, "minimenu.start_selected", 0 ) ) {
+
+    // pick first visible app
     ui_selected = g_categories [ ui_category ] -> refs;
     ui_selected = g_categories [ ui_category ] -> refs;
+
+    // change.. so we pick first visible if option is set .. but now we also try to restore
+    // selection to the last app selected in previous session (if there is one.)
+    char *previous_unique_id = pnd_conf_get_as_char ( g_conf, "minimenu.last_known_app_uid" );
+
+    if ( previous_unique_id ) {
+
+      // 1) we should already be in the right category, since its set in ui_post_scan to minimenu.last_known_catname
+      // 2) so we just pick the app in question..
+      mm_appref_t *previter = g_categories [ ui_category ] -> refs;
+      while ( previter ) {
+       if ( strcmp ( previter -> ref -> unique_id, previous_unique_id ) == 0 ) {
+         break;
+       }
+       previter = previter -> next;
+      }
+
+      if ( previter ) {
+       ui_selected = previter;
+      }
+
+    } // last known app?
+
   }
 #endif
 
   }
 #endif
 
@@ -1401,6 +1426,7 @@ void ui_process_input ( pnd_dbusnotify_handle dbh, pnd_notify_handle nh ) {
          // configure mm
          unsigned char restart = conf_run_menu ( NULL );
          conf_write ( g_conf, conf_determine_location ( g_conf ) );
          // configure mm
          unsigned char restart = conf_run_menu ( NULL );
          conf_write ( g_conf, conf_determine_location ( g_conf ) );
+         conf_write ( g_conf, CONF_PREF_TEMPPATH );
          if ( restart ) {
            emit_and_quit ( MM_RESTART );
          }
          if ( restart ) {
            emit_and_quit ( MM_RESTART );
          }
@@ -1795,6 +1821,17 @@ void ui_push_exec ( void ) {
     return;
   }
 
     return;
   }
 
+  // cache the category/app so we can come back to it another time
+  if ( ui_selected ) {
+    pnd_conf_set_char ( g_conf, "minimenu.last_known_app_uid", ui_selected -> ref -> unique_id );
+  }
+  if ( g_categories [ 0 ] ) {
+    pnd_conf_set_char ( g_conf, "minimenu.last_known_catname", g_categories [ ui_category ] -> catname );
+  }
+
+  // cache last known cat/app to /tmp, so we can use it again later
+  conf_write ( g_conf, CONF_PREF_TEMPPATH );
+
   // was this icon generated from filesystem, or from pnd-file?
   if ( ui_selected -> ref -> object_flags & PND_DISCO_GENERATED ) {
 
   // was this icon generated from filesystem, or from pnd-file?
   if ( ui_selected -> ref -> object_flags & PND_DISCO_GENERATED ) {
 
@@ -2275,6 +2312,9 @@ void ui_set_selected ( mm_appref_t *r ) {
 
   render_mask |= CHANGED_SELECTION;
 
 
   render_mask |= CHANGED_SELECTION;
 
+  // preview pic stuff
+  //
+
   if ( ! pnd_conf_get_as_int_d ( g_conf, "minimenu.load_previews_later", 0 ) ) {
     return; // no desire to defer anything
   }
   if ( ! pnd_conf_get_as_int_d ( g_conf, "minimenu.load_previews_later", 0 ) ) {
     return; // no desire to defer anything
   }
@@ -2735,29 +2775,43 @@ void ui_post_scan ( void ) {
   ui_category = 0;
   ui_catshift = 0;
 
   ui_category = 0;
   ui_catshift = 0;
 
-  // do we have a preferred category to jump to?
+  // do we have a preferred category to jump to? or a last known one?
   char *dc = pnd_conf_get_as_char ( g_conf, "categories.default_cat" );
   char *dc = pnd_conf_get_as_char ( g_conf, "categories.default_cat" );
-  if ( dc ) {
+  char *lastcat = pnd_conf_get_as_char ( g_conf, "minimenu.last_known_catname" );
+  if ( ( dc ) ||
+       ( pnd_conf_get_as_int_d ( g_conf, "minimenu.start_selected", 0 ) && lastcat ) )
+  {
+    char *catpick = NULL;
+
+    if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.start_selected", 0 ) && lastcat ) {
+      catpick = lastcat;
+    } else if ( dc ) {
+      catpick = dc;
+    }
 
     // attempt to find default cat; if we do find it, select it; otherwise
     // default behaviour will pick first cat (ie: usually All)
 
     // attempt to find default cat; if we do find it, select it; otherwise
     // default behaviour will pick first cat (ie: usually All)
-    unsigned int i;
-    for ( i = 0; i < g_categorycount; i++ ) {
-      if ( strcasecmp ( g_categories [ i ] -> catname, dc ) == 0 ) {
-       ui_category = i;
-       // ensure visibility
-       unsigned int screen_width = ui_display_context.screen_width;
-       unsigned int tab_width = pnd_conf_get_as_int ( g_conf, "tabs.tab_width" );
-       if ( ui_category > ui_catshift + ( screen_width / tab_width ) - 1 ) {
-         ui_catshift = ui_category - ( screen_width / tab_width ) + 1;
+    if ( catpick ) {
+      unsigned int i;
+
+      for ( i = 0; i < g_categorycount; i++ ) {
+       if ( strcasecmp ( g_categories [ i ] -> catname, catpick ) == 0 ) {
+         ui_category = i;
+         // ensure visibility
+         unsigned int screen_width = ui_display_context.screen_width;
+         unsigned int tab_width = pnd_conf_get_as_int ( g_conf, "tabs.tab_width" );
+         if ( ui_category > ui_catshift + ( screen_width / tab_width ) - 1 ) {
+           ui_catshift = ui_category - ( screen_width / tab_width ) + 1;
+         }
+         break;
        }
        }
-       break;
       }
       }
-    }
 
 
-    if ( i == g_categorycount ) {
-      pnd_log ( pndn_warning, "  User defined default category '%s' but not found, so using default behaviour\n", dc );
-    }
+      if ( i == g_categorycount ) {
+       pnd_log ( pndn_warning, "  User defined default category or last known cat '%s' but not found, so using default behaviour\n", catpick );
+      }
+
+    } // cat change?
 
   } // default cat
 
 
   } // default cat
 
@@ -3435,6 +3489,7 @@ void ui_menu_context ( mm_appref_t *a ) {
 
          // write conf, so it will take next time
          conf_write ( g_conf, conf_determine_location ( g_conf ) );
 
          // write conf, so it will take next time
          conf_write ( g_conf, conf_determine_location ( g_conf ) );
+         conf_write ( g_conf, CONF_PREF_TEMPPATH );
 
          // can we just 'hide' this guy without reloading all apps? (this is for you, EvilDragon)
          if ( 0 ) {
 
          // can we just 'hide' this guy without reloading all apps? (this is for you, EvilDragon)
          if ( 0 ) {