minimenu fixes so icon-wrap is better handled in edge cases -- pushing right, on...
[pandora-libraries.git] / minimenu / mmui.c
index a45de78..90288e8 100644 (file)
@@ -3,12 +3,16 @@
 #include <stdlib.h>
 #include <limits.h>
 #include <time.h>
+#include <unistd.h>
 #include "SDL.h"
 #include "SDL_audio.h"
 #include "SDL_image.h"
 #include "SDL_ttf.h"
 #include "SDL_gfxPrimitives.h"
 #include "SDL_rotozoom.h"
+#include "SDL_thread.h"
+#include <sys/types.h>
+#include <dirent.h>
 
 #include "pnd_conf.h"
 #include "pnd_logger.h"
@@ -17,6 +21,8 @@
 #include "pnd_discovery.h"
 #include "pnd_apps.h"
 #include "pnd_device.h"
+#include "../lib/pnd_pathiter.h"
+#include "pnd_utility.h"
 
 #include "mmenu.h"
 #include "mmcat.h"
 #include "mmui.h"
 #include "mmwrapcmd.h"
 
+#define CHANGED_NOTHING     (0)
+#define CHANGED_CATEGORY    (1<<0)  /* changed to different category */
+#define CHANGED_SELECTION   (1<<1)  /* changed app selection */
+#define CHANGED_DATAUPDATE  (1<<2)  /* deferred preview pic or icon came in */
+#define CHANGED_APPRELOAD   (1<<3)  /* new set of applications entirely */
+#define CHANGED_EVERYTHING  (1<<4)  /* redraw it all! */
+unsigned int render_mask = CHANGED_EVERYTHING;
+
 /* SDL
  */
 SDL_Surface *sdl_realscreen = NULL;
 unsigned int sdl_ticks = 0;
+SDL_Thread *g_preview_thread = NULL;
+
+enum { sdl_user_ticker = 0,
+       sdl_user_finishedpreview = 1,
+       sdl_user_finishedicon = 2,
+};
 
 /* app state
  */
@@ -139,11 +159,11 @@ unsigned char ui_setup ( void ) {
   }
 
   // grid font
-  sprintf ( fullpath, "%s/%s", g_skinpath, pnd_conf_get_as_char ( g_conf, MMENU_GRID_FONT ) );
-  g_grid_font = TTF_OpenFont ( fullpath, pnd_conf_get_as_int_d ( g_conf, MMENU_GRID_FONTSIZE, 10 ) );
+  sprintf ( fullpath, "%s/%s", g_skinpath, pnd_conf_get_as_char ( g_conf, "grid.font" ) );
+  g_grid_font = TTF_OpenFont ( fullpath, pnd_conf_get_as_int_d ( g_conf, "grid.font_ptsize", 10 ) );
   if ( ! g_grid_font ) {
     pnd_log ( pndn_error, "ERROR: Couldn't load font '%s' for size %u\n",
-             pnd_conf_get_as_char ( g_conf, MMENU_GRID_FONT ), pnd_conf_get_as_int_d ( g_conf, MMENU_GRID_FONTSIZE, 10 ) );
+             pnd_conf_get_as_char ( g_conf, "grid.font" ), pnd_conf_get_as_int_d ( g_conf, "grid.font_ptsize", 10 ) );
     return ( 0 ); // couldn't set up SDL TTF
   }
 
@@ -176,12 +196,16 @@ mm_imgcache_t g_imagecache [ IMG_TRUEMAX ] = {
   { IMG_SELECTED_ALPHAMASK,   "graphics.IMG_SELECTED_ALPHAMASK" },
   { IMG_TAB_SEL,              "graphics.IMG_TAB_SEL" },
   { IMG_TAB_UNSEL,            "graphics.IMG_TAB_UNSEL" },
+  { IMG_TAB_LINE,             "graphics.IMG_TAB_LINE" },
+  { IMG_TAB_LINEL,            "graphics.IMG_TAB_LINEL" },
+  { IMG_TAB_LINER,            "graphics.IMG_TAB_LINER" },
   { IMG_ICON_MISSING,         "graphics.IMG_ICON_MISSING" },
   { IMG_SELECTED_HILITE,      "graphics.IMG_SELECTED_HILITE" },
   { IMG_PREVIEW_MISSING,      "graphics.IMG_PREVIEW_MISSING" },
   { IMG_ARROW_UP,             "graphics.IMG_ARROW_UP", },
   { IMG_ARROW_DOWN,           "graphics.IMG_ARROW_DOWN", },
   { IMG_ARROW_SCROLLBAR,      "graphics.IMG_ARROW_SCROLLBAR", },
+  { IMG_HOURGLASS,            "graphics.IMG_HOURGLASS", },
   { IMG_MAX,                  NULL },
 };
 
@@ -205,7 +229,11 @@ unsigned char ui_imagecache ( char *basepath ) {
       return ( 0 );
     }
 
-    sprintf ( fullpath, "%s/%s", basepath, filename );
+    if ( filename [ 0 ] == '/' ) {
+      strncpy ( fullpath, filename, PATH_MAX );
+    } else {
+      sprintf ( fullpath, "%s/%s", basepath, filename );
+    }
 
     if ( ! ( g_imagecache [ i ].i = IMG_Load ( fullpath ) ) ) {
       pnd_log ( pndn_error, "ERROR: Couldn't load static cache image: %s\n", fullpath );
@@ -222,7 +250,6 @@ unsigned char ui_imagecache ( char *basepath ) {
   //
 
   // scale icons
-  g_imagecache [ IMG_SELECTED_ALPHAMASK ].i = ui_scale_image ( g_imagecache [ IMG_SELECTED_ALPHAMASK ].i, pnd_conf_get_as_int_d ( g_conf, "grid.icon_max_width", 50 ), -1 );
   g_imagecache [ IMG_ICON_MISSING ].i = ui_scale_image ( g_imagecache [ IMG_ICON_MISSING ].i, pnd_conf_get_as_int_d ( g_conf, "grid.icon_max_width", 50 ), -1 );
   // scale text hilight
   g_imagecache [ IMG_SELECTED_HILITE ].i = ui_scale_image ( g_imagecache [ IMG_SELECTED_HILITE ].i, pnd_conf_get_as_int_d ( g_conf, "grid.text_width", 50 ), -1 );
@@ -232,18 +259,47 @@ unsigned char ui_imagecache ( char *basepath ) {
                                                            pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_height", 50 ) );
 
   // set alpha on detail panel
-  SDL_SetAlpha ( g_imagecache [ IMG_DETAIL_BG ].i, SDL_SRCALPHA, pnd_conf_get_as_int_d ( g_conf, "display.detail_bg_alpha", 50 ) );
+  //SDL_SetAlpha ( g_imagecache [ IMG_DETAIL_BG ].i, SDL_SRCALPHA, pnd_conf_get_as_int_d ( g_conf, "display.detail_bg_alpha", 50 ) );
 
   return ( 1 );
 } // ui_imagecache
 
-void ui_render ( unsigned int render_mask ) {
+void ui_render ( void ) {
 
   // 800x480:
   // divide width: 550 / 250
   // divide left side: 5 columns == 110px width
   //   20px buffer either side == 70px wide icon + 20 + 20?
 
+  // what jobs to do during render?
+  //
+
+#define R_BG     (1<<0)
+#define R_TABS   (1<<1)
+#define R_DETAIL (1<<2)
+#define R_GRID   (1<<3)
+
+#define R_ALL (R_BG|R_TABS|R_DETAIL|R_GRID)
+
+  unsigned int render_jobs_b = 0;
+
+  if ( render_mask & CHANGED_EVERYTHING ) {
+    render_jobs_b |= R_ALL;
+  }
+
+  if ( render_mask & CHANGED_SELECTION ) {
+    render_jobs_b |= R_GRID;
+    render_jobs_b |= R_DETAIL;
+  }
+
+  if ( render_mask & CHANGED_CATEGORY ) {
+    render_jobs_b |= R_ALL;
+  }
+
+  render_mask = CHANGED_NOTHING;
+
+  // render everything
+  //
   unsigned int icon_rows;
 
 #define MAXRECTS 200
@@ -256,8 +312,8 @@ void ui_render ( unsigned int render_mask ) {
 
   unsigned int screen_width = pnd_conf_get_as_int_d ( g_conf, "display.screen_width", 800 );
 
-  unsigned char row_max = pnd_conf_get_as_int_d ( g_conf, MMENU_DISP_ROWMAX, 4 );
-  unsigned char col_max = pnd_conf_get_as_int_d ( g_conf, MMENU_DISP_COLMAX, 5 );
+  unsigned char row_max = pnd_conf_get_as_int_d ( g_conf, "grid.row_max", 4 );
+  unsigned char col_max = pnd_conf_get_as_int_d ( g_conf, "grid.col_max", 5 );
 
   unsigned int font_rgba_r = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_r", 200 );
   unsigned int font_rgba_g = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_g", 200 );
@@ -270,6 +326,9 @@ void ui_render ( unsigned int render_mask ) {
   unsigned int icon_offset_x = pnd_conf_get_as_int ( g_conf, "grid.icon_offset_x" );
   unsigned int icon_offset_y = pnd_conf_get_as_int ( g_conf, "grid.icon_offset_y" );
   unsigned int icon_max_width = pnd_conf_get_as_int ( g_conf, "grid.icon_max_width" );
+  unsigned int icon_max_height = pnd_conf_get_as_int ( g_conf, "grid.icon_max_height" );
+  unsigned int sel_icon_offset_x = pnd_conf_get_as_int_d ( g_conf, "grid.sel_offoffset_x", 0 );
+  unsigned int sel_icon_offset_y = pnd_conf_get_as_int_d ( g_conf, "grid.sel_offoffset_y", 0 );
 
   unsigned int text_width = pnd_conf_get_as_int ( g_conf, "grid.text_width" );
   unsigned int text_clip_x = pnd_conf_get_as_int ( g_conf, "grid.text_clip_x" );
@@ -292,6 +351,9 @@ void ui_render ( unsigned int render_mask ) {
   }
 #endif
 
+  // reset touchscreen regions
+  ui_register_reset();
+
   // ensure selection is visible
   if ( ui_selected ) {
 
@@ -299,12 +361,14 @@ void ui_render ( unsigned int render_mask ) {
     int topleft = col_max * ui_rows_scrolled_down;
     int botright = ( col_max * ( ui_rows_scrolled_down + row_max ) - 1 );
 
-    //pnd_log ( PND_LOG_DEFAULT, "index %u tl %u br %u\n", index, topleft, botright );
+    pnd_log ( PND_LOG_DEFAULT, "index %u tl %u br %u\n", index, topleft, botright );
 
     if ( index < topleft ) {
       ui_rows_scrolled_down -= pnd_conf_get_as_int_d ( g_conf, "grid.scroll_increment", 1 );
+      render_jobs_b |= R_ALL;
     } else if ( index > botright ) {
       ui_rows_scrolled_down += pnd_conf_get_as_int_d ( g_conf, "grid.scroll_increment", 1 );
+      render_jobs_b |= R_ALL;
     }
 
     if ( ui_rows_scrolled_down < 0 ) {
@@ -316,41 +380,45 @@ void ui_render ( unsigned int render_mask ) {
   } // ensire visible
 
   // render background
-  if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
-    dest -> x = 0;
-    dest -> y = 0;
-    dest -> w = sdl_realscreen -> w;
-    dest -> h = sdl_realscreen -> h;
-    SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, NULL /* whole image */, sdl_realscreen, dest /* 0,0 */ );
-    //SDL_UpdateRects ( sdl_realscreen, 1, &dest );
-    dest++;
-  }
+  if ( render_jobs_b & R_BG ) {
 
-  // tabmask
-  if ( g_imagecache [ IMG_BACKGROUND_TABMASK ].i ) {
-    dest -> x = 0;
-    dest -> y = 0;
-    dest -> w = sdl_realscreen -> w;
-    dest -> h = sdl_realscreen -> h;
-    SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_TABMASK ].i, NULL /* whole image */, sdl_realscreen, dest /* 0,0 */ );
-    //SDL_UpdateRects ( sdl_realscreen, 1, &dest );
-    dest++;
-  }
+    if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
+      dest -> x = 0;
+      dest -> y = 0;
+      dest -> w = sdl_realscreen -> w;
+      dest -> h = sdl_realscreen -> h;
+      SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, NULL /* whole image */, sdl_realscreen, dest /* 0,0 */ );
+      dest++;
+    }
+
+    // tabmask
+    if ( g_imagecache [ IMG_BACKGROUND_TABMASK ].i ) {
+      dest -> x = 0;
+      dest -> y = 0;
+      dest -> w = sdl_realscreen -> w;
+      dest -> h = sdl_realscreen -> h;
+      SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_TABMASK ].i, NULL /* whole image */, sdl_realscreen, dest /* 0,0 */ );
+      dest++;
+    }
+
+  } // r_bg
 
   // tabs
   if ( g_imagecache [ IMG_TAB_SEL ].i && g_imagecache [ IMG_TAB_UNSEL ].i ) {
     unsigned int tab_width = pnd_conf_get_as_int ( g_conf, "tabs.tab_width" );
     unsigned int tab_height = pnd_conf_get_as_int ( g_conf, "tabs.tab_height" );
+    unsigned int tab_selheight = pnd_conf_get_as_int ( g_conf, "tabs.tab_selheight" );
     unsigned int tab_offset_x = pnd_conf_get_as_int ( g_conf, "tabs.tab_offset_x" );
     unsigned int tab_offset_y = pnd_conf_get_as_int ( g_conf, "tabs.tab_offset_y" );
     unsigned int text_offset_x = pnd_conf_get_as_int ( g_conf, "tabs.text_offset_x" );
     unsigned int text_offset_y = pnd_conf_get_as_int ( g_conf, "tabs.text_offset_y" );
     unsigned int text_width = pnd_conf_get_as_int ( g_conf, "tabs.text_width" );
+    unsigned int maxtab = ( screen_width / tab_width ) < g_categorycount ? ( screen_width / tab_width ) + ui_catshift : g_categorycount + ui_catshift;
+    unsigned int maxtabspot = ( screen_width / tab_width );
 
+    // draw tabs with categories
     for ( col = ui_catshift;
-         col < ( 
-                  ( screen_width / tab_width ) < g_categorycount ? ( screen_width / tab_width ) + ui_catshift : g_categorycount + ui_catshift
-               );
+         col < maxtab;
          col++ )
     {
 
@@ -364,35 +432,89 @@ void ui_render ( unsigned int render_mask ) {
       // draw tab
       src.x = 0;
       src.y = 0;
+#if 0
       src.w = tab_width;
-      src.h = tab_height;
+      if ( col == ui_category ) {
+       src.h = tab_selheight;
+      } else {
+       src.h = tab_height;
+      }
+#else
+      src.w = s -> w;
+      src.h = s -> h;
+#endif
       dest -> x = tab_offset_x + ( (col-ui_catshift) * tab_width );
       dest -> y = tab_offset_y;
-      //pnd_log ( pndn_debug, "tab %u at %ux%u\n", col, dest.x, dest.y );
-      SDL_BlitSurface ( s, &src, sdl_realscreen, dest );
-      //SDL_UpdateRects ( sdl_realscreen, 1, &dest );
-      dest++;
 
-      // draw text
-      SDL_Surface *rtext;
-      SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
-      rtext = TTF_RenderText_Blended ( g_tab_font, g_categories [ col ].catname, tmpfontcolor );
-      src.x = 0;
-      src.y = 0;
-      src.w = rtext -> w < text_width ? rtext -> w : text_width;
-      src.h = rtext -> h;
-      dest -> x = tab_offset_x + ( (col-ui_catshift) * tab_width ) + text_offset_x;
-      dest -> y = tab_offset_y + text_offset_y;
-      SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
-      SDL_FreeSurface ( rtext );
-      dest++;
+      // store touch info
+      ui_register_tab ( col, dest -> x, dest -> y, tab_width, tab_height );
+
+      if ( render_jobs_b & R_TABS ) {
+       //pnd_log ( pndn_debug, "tab %u at %ux%u\n", col, dest.x, dest.y );
+       SDL_BlitSurface ( s, &src, sdl_realscreen, dest );
+       dest++;
+
+       // draw tab line
+       if ( col == ui_category ) {
+         // no line for selected tab
+       } else {
+         if ( col - ui_catshift == 0 ) {
+           s = g_imagecache [ IMG_TAB_LINEL ].i;
+         } else if ( col - ui_catshift == maxtabspot - 1 ) {
+           s = g_imagecache [ IMG_TAB_LINER ].i;
+         } else {
+           s = g_imagecache [ IMG_TAB_LINE ].i;
+         }
+         dest -> x = tab_offset_x + ( (col-ui_catshift) * tab_width );
+         dest -> y = tab_offset_y + tab_height;
+         SDL_BlitSurface ( s, NULL /* whole image */, sdl_realscreen, dest );
+         dest++;
+       }
+
+       // draw text
+       SDL_Surface *rtext;
+       SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
+       rtext = TTF_RenderText_Blended ( g_tab_font, g_categories [ col ].catname, tmpfontcolor );
+       src.x = 0;
+       src.y = 0;
+       src.w = rtext -> w < text_width ? rtext -> w : text_width;
+       src.h = rtext -> h;
+       dest -> x = tab_offset_x + ( (col-ui_catshift) * tab_width ) + text_offset_x;
+       dest -> y = tab_offset_y + text_offset_y;
+       SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
+       SDL_FreeSurface ( rtext );
+       dest++;
+
+      } // r_tabs
 
     } // for
 
+    if ( render_jobs_b & R_TABS ) {
+
+      // draw tab lines under where tabs would be if we had categories
+      for ( /* foo */; col < maxtabspot; col++ ) {
+       SDL_Surface *s;
+
+       if ( col - ui_catshift == 0 ) {
+         s = g_imagecache [ IMG_TAB_LINEL ].i;
+       } else if ( col - ui_catshift == maxtabspot - 1 ) {
+         s = g_imagecache [ IMG_TAB_LINER ].i;
+       } else {
+         s = g_imagecache [ IMG_TAB_LINE ].i;
+       }
+       dest -> x = tab_offset_x + ( (col-ui_catshift) * tab_width );
+       dest -> y = tab_offset_y + tab_height;
+       SDL_BlitSurface ( s, NULL /* whole image */, sdl_realscreen, dest );
+       dest++;
+
+      } // for
+
+    } // r_tabs
+
   } // tabs
 
   // scroll bars and arrows
-  {
+  if ( render_jobs_b & R_BG ) {
     unsigned char show_bar = 0;
 
     // up?
@@ -400,7 +522,6 @@ void ui_render ( unsigned int render_mask ) {
       dest -> x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_up_x", 450 );
       dest -> y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_up_y", 80 );
       SDL_BlitSurface ( g_imagecache [ IMG_ARROW_UP ].i, NULL /* whole image */, sdl_realscreen, dest );
-      //SDL_UpdateRects ( sdl_realscreen, 1, &dest );
       dest++;
 
       show_bar = 1;
@@ -411,7 +532,6 @@ void ui_render ( unsigned int render_mask ) {
       dest -> x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_down_x", 450 );
       dest -> y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_down_y", 80 );
       SDL_BlitSurface ( g_imagecache [ IMG_ARROW_DOWN ].i, NULL /* whole image */, sdl_realscreen, dest );
-      //SDL_UpdateRects ( sdl_realscreen, 1, &dest );
       dest++;
 
       show_bar = 1;
@@ -426,141 +546,168 @@ void ui_render ( unsigned int render_mask ) {
       dest -> x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_x", 450 );
       dest -> y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_y", 100 );
       SDL_BlitSurface ( g_imagecache [ IMG_ARROW_SCROLLBAR ].i, &src /* whole image */, sdl_realscreen, dest );
-      //SDL_UpdateRects ( sdl_realscreen, 1, &dest );
       dest++;
     } // bar
 
-  } // scroll bars
+  } // r_bg, scroll bars
 
   // render detail pane bg
-  if ( pnd_conf_get_as_int_d ( g_conf, "detailpane.show", 1 ) ) {
+  if ( render_jobs_b & R_DETAIL ) {
+
+    if ( pnd_conf_get_as_int_d ( g_conf, "detailpane.show", 1 ) ) {
+
+      // render detail bg
+      if ( g_imagecache [ IMG_DETAIL_BG ].i ) {
+       src.x = 0; // pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
+       src.y = 0; // pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
+       src.w = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_PANEL ].i)) -> w;
+       src.h = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_PANEL ].i)) -> h;
+       dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
+       dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
+       SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
+       dest++;
+      }
 
-    if ( g_imagecache [ IMG_DETAIL_BG ].i ) {
-      src.x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
-      src.y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
-      src.w = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_PANEL ].i)) -> w;
-      src.h = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_PANEL ].i)) -> h;
-      dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
-      dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
-      SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
-      //SDL_UpdateRects ( sdl_realscreen, 1, &dest );
-      dest++;
-    }
+      // render detail pane
+      if ( g_imagecache [ IMG_DETAIL_PANEL ].i ) {
+       dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
+       dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
+       SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_PANEL ].i, NULL /* whole image */, sdl_realscreen, dest );
+       dest++;
+      }
 
-    // render detail pane
-    if ( g_imagecache [ IMG_DETAIL_PANEL ].i ) {
-      dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
-      dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
-      SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_PANEL ].i, NULL /* whole image */, sdl_realscreen, dest );
-      //SDL_UpdateRects ( sdl_realscreen, 1, &dest );
-      dest++;
-    }
+    } // detailpane frame/bg
 
-  } // detailpane frame/bg
+  } // r_details
 
   // anything to render?
-  if ( g_categories [ ui_category ].refs ) {
+  if ( render_jobs_b & R_GRID ) {
 
-    appiter = g_categories [ ui_category ].refs;
-    row = 0;
-    displayrow = 0;
+    // if just rendering grid, and nothing else, better clear it first
+    if ( ! ( render_jobs_b & R_BG ) ) {
+      if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
+       src.x = grid_offset_x;
+       src.y = grid_offset_y + sel_icon_offset_y;
+       src.w = col_max * cell_width;
+       src.h = row_max * cell_height;
 
-    // until we run out of apps, or run out of space
-    while ( appiter != NULL ) {
+       dest -> x = grid_offset_x;
+       dest -> y = grid_offset_y + sel_icon_offset_y;
 
-      for ( col = 0; col < col_max && appiter != NULL; col++ ) {
+       SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, &src, sdl_realscreen, dest );
+       dest++;
 
-       // do we even need to render it? or are we suppressing it due to rows scrolled off the top?
-       if ( row >= ui_rows_scrolled_down ) {
+      }
+    }
 
-         // selected? show hilights
-         if ( appiter == ui_selected ) {
-           // icon
-           dest -> x = grid_offset_x + ( col * cell_width ) + icon_offset_x;
-           dest -> y = grid_offset_y + ( displayrow * cell_height ) + icon_offset_y;
-           SDL_BlitSurface ( g_imagecache [ IMG_SELECTED_ALPHAMASK ].i, NULL /* all */, sdl_realscreen, dest );
-           //SDL_UpdateRects ( sdl_realscreen, 1, &dest );
-           dest++;
-           // text
-           dest -> x = grid_offset_x + ( col * cell_width ) + text_clip_x;
-           dest -> y = grid_offset_y + ( displayrow * cell_height ) + pnd_conf_get_as_int ( g_conf, "grid.text_hilite_offset_y" );
-           SDL_BlitSurface ( g_imagecache [ IMG_SELECTED_HILITE ].i, NULL /* all */, sdl_realscreen, dest );
-           //SDL_UpdateRects ( sdl_realscreen, 1, &dest );
-           dest++;
-         } // selected?
-
-         // show icon
-         mm_cache_t *ic = cache_query_icon ( appiter -> ref -> unique_id );
-         SDL_Surface *iconsurface;
-         if ( ic ) {
-           iconsurface = ic -> i;
-         } else {
-           //pnd_log ( pndn_warning, "WARNING: TBD: Need Missin-icon icon for '%s'\n", IFNULL(appiter -> ref -> title_en,"No Name") );
-           iconsurface = g_imagecache [ IMG_ICON_MISSING ].i;
-         }
-         if ( iconsurface ) {
-           //pnd_log ( pndn_debug, "Got an icon for '%s'\n", IFNULL(appiter -> ref -> title_en,"No Name") );
+    if ( g_categories [ ui_category ].refs ) {
 
-           src.x = 0;
-           src.y = 0;
-           src.w = 60;
-           src.h = 60;
-           dest -> x = grid_offset_x + ( col * cell_width ) + icon_offset_x + (( icon_max_width - iconsurface -> w ) / 2);
-           dest -> y = grid_offset_y + ( displayrow * cell_height ) + icon_offset_y;
+      appiter = g_categories [ ui_category ].refs;
+      row = 0;
+      displayrow = 0;
 
-           SDL_BlitSurface ( iconsurface, &src, sdl_realscreen, dest );
-           //SDL_UpdateRects ( sdl_realscreen, 1, &dest );
-           dest++;
+      // until we run out of apps, or run out of space
+      while ( appiter != NULL ) {
 
-         }
+       for ( col = 0; col < col_max && appiter != NULL; col++ ) {
+
+         // do we even need to render it? or are we suppressing it due to rows scrolled off the top?
+         if ( row >= ui_rows_scrolled_down ) {
 
-         // show text
-         if ( appiter -> ref -> title_en ) {
-           SDL_Surface *rtext;
-           SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
-           rtext = TTF_RenderText_Blended ( g_grid_font, appiter -> ref -> title_en, tmpfontcolor );
-           src.x = 0;
-           src.y = 0;
-           src.w = text_width < rtext -> w ? text_width : rtext -> w;
-           src.h = rtext -> h;
-           if ( rtext -> w > text_width ) {
+           // selected? show hilights
+           if ( appiter == ui_selected ) {
+             SDL_Surface *s = g_imagecache [ IMG_SELECTED_ALPHAMASK ].i;
+             // icon
+             //dest -> x = grid_offset_x + ( col * cell_width ) + icon_offset_x + ( ( icon_max_width - s -> w ) / 2 );
+             dest -> x = grid_offset_x + ( col * cell_width ) + icon_offset_x + sel_icon_offset_x;
+             //dest -> y = grid_offset_y + ( displayrow * cell_height ) + icon_offset_y + ( ( icon_max_height - s -> h ) / 2 );
+             dest -> y = grid_offset_y + ( displayrow * cell_height ) + icon_offset_y + sel_icon_offset_y;
+             SDL_BlitSurface ( s, NULL /* all */, sdl_realscreen, dest );
+             dest++;
+             // text
              dest -> x = grid_offset_x + ( col * cell_width ) + text_clip_x;
+             dest -> y = grid_offset_y + ( displayrow * cell_height ) + pnd_conf_get_as_int ( g_conf, "grid.text_hilite_offset_y" );
+             SDL_BlitSurface ( g_imagecache [ IMG_SELECTED_HILITE ].i, NULL /* all */, sdl_realscreen, dest );
+             dest++;
+           } // selected?
+
+           // show icon
+           mm_cache_t *ic = cache_query_icon ( appiter -> ref -> unique_id );
+           SDL_Surface *iconsurface;
+           if ( ic ) {
+             iconsurface = ic -> i;
            } else {
-             dest -> x = grid_offset_x + ( col * cell_width ) + text_offset_x - ( rtext -> w / 2 );
+             //pnd_log ( pndn_warning, "WARNING: TBD: Need Missin-icon icon for '%s'\n", IFNULL(appiter -> ref -> title_en,"No Name") );
+             iconsurface = g_imagecache [ IMG_ICON_MISSING ].i;
            }
-           dest -> y = grid_offset_y + ( displayrow * cell_height ) + text_offset_y;
-           SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
-           SDL_FreeSurface ( rtext );
-           dest++;
-         }
+           if ( iconsurface ) {
+             //pnd_log ( pndn_debug, "Got an icon for '%s'\n", IFNULL(appiter -> ref -> title_en,"No Name") );
 
-       } // display now? or scrolled away..
+             src.x = 0;
+             src.y = 0;
+             src.w = 60;
+             src.h = 60;
+             dest -> x = grid_offset_x + ( col * cell_width ) + icon_offset_x + (( icon_max_width - iconsurface -> w ) / 2);
+             dest -> y = grid_offset_y + ( displayrow * cell_height ) + icon_offset_y + (( icon_max_height - iconsurface -> h ) / 2);
 
-       // next
-       appiter = appiter -> next;
+             SDL_BlitSurface ( iconsurface, &src, sdl_realscreen, dest );
 
-      } // for column 1...X
+             // store touch info
+             ui_register_app ( appiter, dest -> x, dest -> y, src.w, src.h );
 
-      if ( row >= ui_rows_scrolled_down ) {
-       displayrow++;
-      }
+             dest++;
+
+           }
 
-      row ++;
+           // show text
+           if ( appiter -> ref -> title_en ) {
+             SDL_Surface *rtext;
+             SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
+             rtext = TTF_RenderText_Blended ( g_grid_font, appiter -> ref -> title_en, tmpfontcolor );
+             src.x = 0;
+             src.y = 0;
+             src.w = text_width < rtext -> w ? text_width : rtext -> w;
+             src.h = rtext -> h;
+             if ( rtext -> w > text_width ) {
+               dest -> x = grid_offset_x + ( col * cell_width ) + text_clip_x;
+             } else {
+               dest -> x = grid_offset_x + ( col * cell_width ) + text_offset_x - ( rtext -> w / 2 );
+             }
+             dest -> y = grid_offset_y + ( displayrow * cell_height ) + text_offset_y;
+             SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
+             SDL_FreeSurface ( rtext );
+             dest++;
+           }
 
-      // are we done displaying rows?
-      if ( displayrow >= row_max ) {
-       break;
-      }
+         } // display now? or scrolled away..
 
-    } // while
+         // next
+         appiter = appiter -> next;
 
-  } else {
-    // no apps to render?
-    pnd_log ( pndn_rem, "No applications to render?\n" );
-  } // apps to renser?
+       } // for column 1...X
+
+       if ( row >= ui_rows_scrolled_down ) {
+         displayrow++;
+       }
+
+       row ++;
+
+       // are we done displaying rows?
+       if ( displayrow >= row_max ) {
+         break;
+       }
+
+      } // while
+
+    } else {
+      // no apps to render?
+      pnd_log ( pndn_rem, "No applications to render?\n" );
+    } // apps to renser?
+
+  } // r_grid
 
   // detail panel
-  if ( ui_selected ) {
+  if ( ui_selected && render_jobs_b & R_DETAIL ) {
 
     unsigned int cell_offset_x = pnd_conf_get_as_int ( g_conf, "detailtext.cell_offset_x" );
     unsigned int cell_offset_y = pnd_conf_get_as_int ( g_conf, "detailtext.cell_offset_y" );
@@ -588,6 +735,7 @@ void ui_render ( unsigned int render_mask ) {
     }
 
     // category
+#if 0
     if ( ui_selected -> ref -> main_category ) {
 
       sprintf ( buffer, "Category: %s", ui_selected -> ref -> main_category );
@@ -606,6 +754,7 @@ void ui_render ( unsigned int render_mask ) {
       dest++;
       desty += src.h;
     }
+#endif
 
     // clock
     if ( ui_selected -> ref -> clockspeed ) {
@@ -627,6 +776,74 @@ void ui_render ( unsigned int render_mask ) {
       desty += src.h;
     }
 
+    // show sub-app# on right side of cpu clock?
+    //if ( ui_selected -> ref -> subapp_number )
+    {
+      sprintf ( buffer, "(app#%u)", ui_selected -> ref -> subapp_number );
+
+      SDL_Surface *rtext;
+      SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
+      rtext = TTF_RenderText_Blended ( g_grid_font, buffer, tmpfontcolor );
+      dest -> x = cell_offset_x + cell_width - rtext -> w;
+      dest -> y = desty - src.h;
+      SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
+      SDL_FreeSurface ( rtext );
+      dest++;
+    }
+
+    // info hint
+#if 0 // merged into hint-line
+    if ( ui_selected -> ref -> info_filename ) {
+
+      sprintf ( buffer, "Documentation - hit Y" );
+
+      SDL_Surface *rtext;
+      SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
+      rtext = TTF_RenderText_Blended ( g_detailtext_font, buffer, tmpfontcolor );
+      src.x = 0;
+      src.y = 0;
+      src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
+      src.h = rtext -> h;
+      dest -> x = cell_offset_x;
+      dest -> y = desty;
+      SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
+      SDL_FreeSurface ( rtext );
+      dest++;
+      desty += src.h;
+    }
+#endif
+
+    // notes
+    if ( ui_selected -> ovrh ) {
+      char *n;
+      unsigned char i;
+      char buffer [ 50 ];
+
+      desty += 5; // a touch of spacing can't hurt
+
+      for ( i = 1; i < 4; i++ ) {
+       sprintf ( buffer, "Application-%u.note-%u", ui_selected -> ref -> subapp_number, i );
+       n = pnd_conf_get_as_char ( ui_selected -> ovrh, buffer );
+
+       if ( n ) {
+         SDL_Surface *rtext;
+         SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
+         rtext = TTF_RenderText_Blended ( g_detailtext_font, n, tmpfontcolor );
+         src.x = 0;
+         src.y = 0;
+         src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
+         src.h = rtext -> h;
+         dest -> x = cell_offset_x;
+         dest -> y = desty;
+         SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
+         SDL_FreeSurface ( rtext );
+         dest++;
+         desty += rtext -> h;
+       }
+      } // for
+
+    } // r_detail -> notes
+
     // preview pic
     mm_cache_t *ic = cache_query_preview ( ui_selected -> ref -> unique_id );
     SDL_Surface *previewpic;
@@ -642,20 +859,25 @@ void ui_render ( unsigned int render_mask ) {
        ( ( pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 50 ) - previewpic -> w ) / 2 );
       dest -> y = pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_offset_y", 50 );
       SDL_BlitSurface ( previewpic, NULL /* whole image */, sdl_realscreen, dest );
-      //SDL_UpdateRects ( sdl_realscreen, 1, &dest );
       dest++;
     }
 
-  } // selected?
+  } // r_detail && selected?
 
   // extras
   //
 
   // battery
-  if ( 1 ) {
-    unsigned char batterylevel = pnd_device_get_battery_gauge_perc();
+  if ( render_jobs_b & R_BG ) {
+    static int last_battlevel = 0;
+    static unsigned char batterylevel = 0;
     char buffer [ 100 ];
 
+    if ( time ( NULL ) - last_battlevel > 60 ) {
+      batterylevel = pnd_device_get_battery_gauge_perc();
+      last_battlevel = time ( NULL );
+    }
+
     sprintf ( buffer, "Battery: %u%%", batterylevel );
 
     SDL_Surface *rtext;
@@ -670,19 +892,47 @@ void ui_render ( unsigned int render_mask ) {
 
   // hints
   if ( pnd_conf_get_as_char ( g_conf, "display.hintline" ) ) {
-    char *buffer = pnd_conf_get_as_char ( g_conf, "display.hintline" );
+    char *buffer;
+    unsigned int hintx, hinty;
+    hintx = pnd_conf_get_as_int_d ( g_conf, "display.hint_x", 40 );
+    hinty = pnd_conf_get_as_int_d ( g_conf, "display.hint_y", 450 );
+    static unsigned int lastwidth = 3000;
+
+    if ( ui_selected && ui_selected -> ref -> info_filename ) {
+      buffer = "Documentation - hit Y";
+    } else {
+      buffer = pnd_conf_get_as_char ( g_conf, "display.hintline" );
+    }
+
     SDL_Surface *rtext;
     SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
     rtext = TTF_RenderText_Blended ( g_grid_font, buffer, tmpfontcolor );
-    dest -> x = pnd_conf_get_as_int_d ( g_conf, "display.hint_x", 40 );
-    dest -> y = pnd_conf_get_as_int_d ( g_conf, "display.hint_y", 450 );
+
+    // clear bg
+    if ( ! ( render_jobs_b & R_BG ) ) {
+      src.x = hintx;
+      src.y = hinty;
+      src.w = lastwidth;
+      src.h = rtext -> h;
+      dest -> x = hintx;
+      dest -> y = hinty;
+      SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_TABMASK ].i, &src, sdl_realscreen, dest );
+      dest++;
+      lastwidth = rtext -> w;
+    }
+
+    // now render text
+    dest -> x = hintx;
+    dest -> y = hinty;
     SDL_BlitSurface ( rtext, NULL /* all */, sdl_realscreen, dest );
     SDL_FreeSurface ( rtext );
     dest++;
   }
 
-  // hints
-  if ( pnd_conf_get_as_int_d ( g_conf, "display.clock_x", -1 ) != -1 ) {
+  // clock time
+  if ( render_jobs_b & R_BG &&
+       pnd_conf_get_as_int_d ( g_conf, "display.clock_x", -1 ) != -1 )
+  {
     char buffer [ 50 ];
 
     time_t t = time ( NULL );
@@ -700,6 +950,8 @@ void ui_render ( unsigned int render_mask ) {
   }
 
   // update all the rects and send it all to sdl
+  // - at this point, we could probably just do 1 rect, of the
+  //   whole screen, and be faster :/
   SDL_UpdateRects ( sdl_realscreen, dest - rects, rects );
 
 } // ui_render
@@ -708,7 +960,7 @@ void ui_process_input ( unsigned char block_p ) {
   SDL_Event event;
 
   unsigned char ui_event = 0; // if we get a ui event, flip to 1 and break
-  static ui_sdl_button_e ui_mask = uisb_none; // current buttons down
+  //static ui_sdl_button_e ui_mask = uisb_none; // current buttons down
 
   while ( ! ui_event &&
          block_p ? SDL_WaitEvent ( &event ) : SDL_PollEvent ( &event ) )
@@ -719,24 +971,59 @@ void ui_process_input ( unsigned char block_p ) {
     case SDL_USEREVENT:
       // update something
 
-      if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.load_previews_later", 0 ) ) {
+      if ( event.user.code == sdl_user_ticker ) {
 
-       pnd_log ( pndn_debug, "Deferred preview pic load ----------\n" );
+       // timer went off, time to load something
+       if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.load_previews_later", 0 ) ) {
 
-       // load the preview pics now!
-       pnd_disco_t *iter = ui_selected -> ref;
+         // load the preview pics now!
+         pnd_disco_t *iter = ui_selected -> ref;
 
-       if ( iter -> preview_pic1 &&
-            ! cache_preview ( iter, pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 200 ), pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_height", 180 ) ) )
-       {
-         pnd_log ( pndn_debug, "  Couldn't load preview pic: '%s' -> '%s'\n", IFNULL(iter->title_en,"No Name"), iter -> preview_pic1 );
+         if ( iter -> preview_pic1 ) {
+
+           if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.threaded_preview", 0 ) ) {
+             // load in bg thread, make user experience chuggy
+
+             g_preview_thread = SDL_CreateThread ( (void*)ui_threaded_defered_preview, iter );
+
+             if ( ! g_preview_thread ) {
+               pnd_log ( pndn_error, "ERROR: Couldn't create preview thread\n" );
+             }
+
+           } else {
+             // load it now, make user wait
+
+             if ( ! cache_preview ( iter, pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 200 ),
+                                    pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_height", 180 ) )
+                )
+             {
+               pnd_log ( pndn_debug, "  Couldn't load preview pic: '%s' -> '%s'\n",
+                         IFNULL(iter->title_en,"No Name"), iter -> preview_pic1 );
+             }
+
+           } // threaded?
+
+         } // got a preview at all?
+
+         ui_event++;
        }
 
-       pnd_log ( pndn_debug, "Deferred preview pic load finish ---\n" );
+      } else if ( event.user.code == sdl_user_finishedpreview ) {
+
+       // if we just finished the one we happen to be looking at, better redraw now; otherwise, if
+       // we finished another, no big woop
+       if ( ui_selected && event.user.data1 == ui_selected -> ref ) {
+         ui_event++;
+       }
 
+      } else if ( event.user.code == sdl_user_finishedicon ) {
+       // redraw, so we can show the newly loaded icon
        ui_event++;
+
       }
 
+      render_mask |= CHANGED_EVERYTHING;
+
       break;
 
 #if 0 // joystick motion
@@ -859,19 +1146,32 @@ void ui_process_input ( unsigned char block_p ) {
       } else if ( event.key.keysym.sym == SDLK_x || event.key.keysym.sym == SDLK_RCTRL ) {
        ui_push_rtrigger();
        ui_event++;
+      } else if ( event.key.keysym.sym == SDLK_y || event.key.keysym.sym == SDLK_PAGEUP ) {
+       // info
+       if ( ui_selected ) {
+         ui_show_info ( pnd_run_script, ui_selected -> ref );
+         ui_event++;
+       }
 
       } else if ( event.key.keysym.sym == SDLK_LALT ) { // start button
+       ui_push_exec();
+       ui_event++;
+
+      } else if ( event.key.keysym.sym == SDLK_LCTRL /*LALT*/ ) { // select button
        char *opts [ 20 ] = {
          "Return to Minimenu",
          "Shutdown Pandora",
          "Rescan for Applications",
+         "Cache previews to SD now",
          "Run xfce4 from Minimenu",
-         "Set to full desktop and reboot",
-         "Set to pmenu and reboot",
+         "Run a terminal/console",
+         "Exit and run xfce4",
+         "Exit and run pmenu",
          "Quit (<- beware)",
+         "Select a Minimenu skin",
          "About Minimenu"
        };
-       int sel = ui_modal_single_menu ( opts, 8, "Minimenu", "Enter to select; other to return." );
+       int sel = ui_modal_single_menu ( opts, 11, "Minimenu", "Enter to select; other to return." );
 
        char buffer [ 100 ];
        if ( sel == 0 ) {
@@ -882,30 +1182,80 @@ void ui_process_input ( unsigned char block_p ) {
          system ( buffer );
        } else if ( sel == 2 ) {
          // rescan apps
+         pnd_log ( pndn_debug, "Freeing up applications\n" );
+         applications_free();
+         pnd_log ( pndn_debug, "Rescanning applications\n" );
+         applications_scan();
+         // reset view
+         ui_selected = NULL;
+         ui_rows_scrolled_down = 0;
        } else if ( sel == 3 ) {
+         // cache preview to SD now
+         extern pnd_box_handle g_active_apps;
+         pnd_box_handle h = g_active_apps;
+
+         unsigned int maxwidth, maxheight;
+         maxwidth = pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 200 );
+         maxheight = pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_height", 180 );
+
+         pnd_disco_t *iter = pnd_box_get_head ( h );
+
+         while ( iter ) {
+
+           // cache it
+           if ( ! cache_preview ( iter, maxwidth, maxheight ) ) {
+             pnd_log ( pndn_debug, "Force cache: Couldn't load preview pic: '%s' -> '%s'\n",
+                       IFNULL(iter->title_en,"No Name"), iter -> preview_pic1 );
+           }
+
+           // next
+           iter = pnd_box_get_next ( iter );
+         } // while
+
+       } else if ( sel == 4 ) {
          // run xfce
          char buffer [ PATH_MAX ];
          sprintf ( buffer, "%s %s\n", MM_RUN, "/usr/bin/startxfce4" );
          emit_and_quit ( buffer );
-       } else if ( sel == 4 ) {
+       } else if ( sel == 5 ) {
+         // run terminal
+         char *argv[5];
+         argv [ 0 ] = pnd_conf_get_as_char ( g_conf, "utility.terminal" );
+         argv [ 1 ] = NULL;
+
+         if ( argv [ 0 ] ) {
+           ui_forkexec ( argv );
+         }
+
+       } else if ( sel == 6 ) {
          // set env to xfce
          sprintf ( buffer, "echo startxfce4 > /tmp/gui.load" );
          system ( buffer );
-         sprintf ( buffer, "sudo poweroff" );
-         system ( buffer );
-       } else if ( sel == 5 ) {
+         emit_and_quit ( buffer );
+         //sprintf ( buffer, "sudo poweroff" );
+         //system ( buffer );
+         exit ( 0 );
+       } else if ( sel == 7 ) {
          // set env to pmenu
          sprintf ( buffer, "echo pmenu > /tmp/gui.load" );
          system ( buffer );
-         sprintf ( buffer, "sudo poweroff" );
-         system ( buffer );
-       } else if ( sel == 6 ) {
+         emit_and_quit ( buffer );
+         //sprintf ( buffer, "sudo poweroff" );
+         //system ( buffer );
+         exit ( 0 );
+       } else if ( sel == 8 ) {
          emit_and_quit ( MM_QUIT );
-       } else if ( sel == 7 ) {
+       } else if ( sel == 9 ) {
+         // select skin
+         if ( ui_pick_skin() ) {
+           emit_and_quit ( MM_RESTART );
+         }
+       } else if ( sel == 10 ) {
          // about
        }
 
        ui_event++;
+       render_mask |= CHANGED_EVERYTHING;
       }
 
       // extras
@@ -916,18 +1266,19 @@ void ui_process_input ( unsigned char block_p ) {
       break;
 #endif
 
-#if 0 // mouse / touchscreen
+#if 1 // mouse / touchscreen
+#if 0
     case SDL_MOUSEBUTTONDOWN:
       if ( event.button.button == SDL_BUTTON_LEFT ) {
        cb_pointer_press ( gc, event.button.x / g_scale, event.button.y / g_scale );
        ui_event++;
       }
       break;
+#endif
 
     case SDL_MOUSEBUTTONUP:
       if ( event.button.button == SDL_BUTTON_LEFT ) {
-       cb_pointer_release ( gc, event.button.x / g_scale, event.button.y / g_scale );
-       retval |= STAT_pen;
+       ui_touch_act ( event.button.x, event.button.y );
        ui_event++;
       }
       break;
@@ -957,13 +1308,13 @@ void ui_push_left ( unsigned char forcecoil ) {
   // what column we in?
   unsigned int col = ui_determine_screen_col ( ui_selected );
 
-  // are we alreadt at first item?
+  // are we already at first item?
   if ( forcecoil == 0 &&
        pnd_conf_get_as_int_d ( g_conf, "grid.wrap_horiz_samerow", 0 ) &&
        col == 0 )
   {
     unsigned int i = pnd_conf_get_as_int_d ( g_conf, "grid.col_max", 5 ) - 1;
-    while ( i ) {
+    while ( i && ui_selected -> next ) {
       ui_push_right ( 0 );
       i--;
     }
@@ -998,13 +1349,16 @@ void ui_push_right ( unsigned char forcecoil ) {
     // wrap same or no?
     if ( forcecoil == 0 &&
         pnd_conf_get_as_int_d ( g_conf, "grid.wrap_horiz_samerow", 0 ) &&
-        col == pnd_conf_get_as_int_d ( g_conf, "grid.col_max", 5 ) - 1 )
+        // and selected is far-right, or last icon in category (might not be far right)
+        ( ( col == pnd_conf_get_as_int_d ( g_conf, "grid.col_max", 5 ) - 1 ) ||
+          ( ui_selected -> next == NULL ) )
+       )
     {
       // same wrap
-      unsigned int i = pnd_conf_get_as_int_d ( g_conf, "grid.col_max", 5 ) - 1;
-      while ( i ) {
+      //unsigned int i = pnd_conf_get_as_int_d ( g_conf, "grid.col_max", 5 ) - 1;
+      while ( col /*i*/ ) {
        ui_push_left ( 0 );
-       i--;
+       col--; //i--;
       }
 
     } else {
@@ -1026,7 +1380,11 @@ void ui_push_right ( unsigned char forcecoil ) {
 }
 
 void ui_push_up ( void ) {
-  unsigned char col_max = pnd_conf_get_as_int ( g_conf, MMENU_DISP_COLMAX );
+  unsigned char col_max = pnd_conf_get_as_int ( g_conf, "grid.col_max" );
+
+  if ( ! ui_selected ) {
+    return;
+  }
 
   // what row we in?
   unsigned int row = ui_determine_row ( ui_selected );
@@ -1056,7 +1414,7 @@ void ui_push_up ( void ) {
 
     // scroll down to show it
     int r = ui_determine_row ( ui_selected ) - 1;
-    if ( r - pnd_conf_get_as_int ( g_conf, MMENU_DISP_ROWMAX ) > 0 ) {
+    if ( r - pnd_conf_get_as_int ( g_conf, "grid.row_max" ) > 0 ) {
       ui_rows_scrolled_down = (unsigned int) r;
     }
 
@@ -1074,7 +1432,7 @@ void ui_push_up ( void ) {
 }
 
 void ui_push_down ( void ) {
-  unsigned char col_max = pnd_conf_get_as_int ( g_conf, MMENU_DISP_COLMAX );
+  unsigned char col_max = pnd_conf_get_as_int ( g_conf, "grid.col_max" );
 
   if ( ui_selected ) {
 
@@ -1103,6 +1461,8 @@ void ui_push_down ( void ) {
 
       ui_rows_scrolled_down = 0;
 
+      render_mask |= CHANGED_EVERYTHING;
+
     } else {
 
       while ( col_max ) {
@@ -1122,16 +1482,8 @@ void ui_push_down ( void ) {
 void ui_push_exec ( void ) {
 
   if ( ui_selected ) {
+    pnd_apps_exec_disco ( pnd_run_script, ui_selected -> ref, PND_EXEC_OPTION_NORUN, NULL );
     char buffer [ PATH_MAX ];
-    sprintf ( buffer, "%s/%s", ui_selected -> ref -> object_path, ui_selected -> ref -> object_filename );
-    pnd_apps_exec ( pnd_run_script,
-                   buffer,
-                   ui_selected -> ref -> unique_id,
-                   ui_selected -> ref -> exec,
-                   ui_selected -> ref -> startdir,
-                   ui_selected -> ref -> execargs,
-                   atoi ( ui_selected -> ref -> clockspeed ),
-                   PND_EXEC_OPTION_NORUN );
     sprintf ( buffer, "%s %s\n", MM_RUN, pnd_apps_exec_runline() );
     emit_and_quit ( buffer );
   }
@@ -1163,6 +1515,8 @@ void ui_push_ltrigger ( void ) {
   // unscroll
   ui_rows_scrolled_down = 0;
 
+  render_mask |= CHANGED_CATEGORY;
+
   return;
 }
 
@@ -1193,6 +1547,8 @@ void ui_push_rtrigger ( void ) {
   // unscroll
   ui_rows_scrolled_down = 0;
 
+  render_mask |= CHANGED_CATEGORY;
+
   return;
 }
 
@@ -1304,6 +1660,7 @@ void ui_cachescreen ( unsigned char clearscreen, char *filename ) {
 
   SDL_Rect rects [ 4 ];
   SDL_Rect *dest = rects;
+  SDL_Rect src;
   bzero ( dest, sizeof(SDL_Rect)* 4 );
 
   unsigned int font_rgba_r = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_r", 200 );
@@ -1327,19 +1684,30 @@ void ui_cachescreen ( unsigned char clearscreen, char *filename ) {
       dest++;
     }
 
-  }
+  } else {
+
+    // render background
+    if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
+      src.x = 0;
+      src.y = 0;
+      src.w = sdl_realscreen -> w;
+      src.h = 100;
+      dest -> x = 0;
+      dest -> y = 0;
+      dest -> w = sdl_realscreen -> w;
+      dest -> h = sdl_realscreen -> h;
+      SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, &src, sdl_realscreen, dest );
+      dest++;
+    }
+
+  } // clear it
 
   // render text
   SDL_Surface *rtext;
   SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
   rtext = TTF_RenderText_Blended ( g_big_font, "Caching applications artwork...", tmpfontcolor );
-  if ( clearscreen ) {
-    dest -> x = 20;
-    dest -> y = 20;
-  } else {
-    dest -> x = 20;
-    dest -> y = 40;
-  }
+  dest -> x = 20;
+  dest -> y = 20;
   SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
   SDL_FreeSurface ( rtext );
   dest++;
@@ -1396,6 +1764,8 @@ int ui_selected_index ( void ) {
 static mm_appref_t *timer_ref = NULL;
 void ui_set_selected ( mm_appref_t *r ) {
 
+  render_mask |= CHANGED_SELECTION;
+
   if ( ! pnd_conf_get_as_int_d ( g_conf, "minimenu.load_previews_later", 0 ) ) {
     return; // no desire to defer anything
   }
@@ -1420,7 +1790,9 @@ unsigned int ui_callback_f ( unsigned int t ) {
   }
 
   SDL_Event e;
+  bzero ( &e, sizeof(SDL_Event) );
   e.type = SDL_USEREVENT;
+  e.user.code = sdl_user_ticker;
   SDL_PushEvent ( &e );
 
   return ( 0 );
@@ -1592,3 +1964,337 @@ unsigned char ui_determine_screen_col ( mm_appref_t *a ) {
 
   return ( col );
 }
+
+unsigned char ui_show_info ( char *pndrun, pnd_disco_t *p ) {
+  char *viewer, *searchpath;
+  pnd_conf_handle desktoph;
+
+  // viewer
+  searchpath = pnd_conf_query_searchpath();
+
+  desktoph = pnd_conf_fetch_by_id ( pnd_conf_desktop, searchpath );
+
+  if ( ! desktoph ) {
+    return ( 0 );
+  }
+
+  viewer = pnd_conf_get_as_char ( desktoph, "info.viewer" );
+
+  if ( ! viewer ) {
+    return ( 0 ); // no way to view the file
+  }
+
+  // etc
+  if ( ! p -> unique_id ) {
+    return ( 0 );
+  }
+
+  if ( ! p -> info_filename ) {
+    return ( 0 );
+  }
+
+  if ( ! p -> info_name ) {
+    return ( 0 );
+  }
+
+  if ( ! pndrun ) {
+    return ( 0 );
+  }
+
+  // exec line
+  char args [ 1001 ];
+  char *pargs = args;
+  if ( pnd_conf_get_as_char ( desktoph, "info.viewer_args" ) ) {
+    snprintf ( pargs, 1001, "%s %s",
+              pnd_conf_get_as_char ( desktoph, "info.viewer_args" ), p -> info_filename );
+  } else {
+    pargs = NULL;
+  }
+
+  char pndfile [ 1024 ];
+  if ( p -> object_type == pnd_object_type_directory ) {
+    // for PXML-app-dir, pnd_run.sh doesn't want the PXML.xml.. it just wants the dir-name
+    strncpy ( pndfile, p -> object_path, 1000 );
+  } else if ( p -> object_type == pnd_object_type_pnd ) {
+    // pnd_run.sh wants the full path and filename for the .pnd file
+    snprintf ( pndfile, 1020, "%s/%s", p -> object_path, p -> object_filename );
+  }
+
+  if ( ! pnd_apps_exec ( pndrun, pndfile, p -> unique_id, viewer, p -> startdir, pargs,
+                        p -> clockspeed ? atoi ( p -> clockspeed ) : 0, PND_EXEC_OPTION_NORUN ) )
+  {
+    return ( 0 );
+  }
+
+  pnd_log ( pndn_debug, "Info Exec=%s\n", pnd_apps_exec_runline() );
+
+  // try running it
+  int x;
+  if ( ( x = fork() ) < 0 ) {
+    pnd_log ( pndn_error, "ERROR: Couldn't fork()\n" );
+    return ( 0 );
+  }
+
+  if ( x == 0 ) {
+    execl ( "/bin/sh", "/bin/sh", "-c", pnd_apps_exec_runline(), (char*)NULL );
+    pnd_log ( pndn_error, "ERROR: Couldn't exec(%s)\n", pnd_apps_exec_runline() );
+    return ( 0 );
+  }
+
+  return ( 1 );
+}
+
+typedef struct {
+  SDL_Rect r;
+  int catnum;
+  mm_appref_t *ref;
+} ui_touch_t;
+#define MAXTOUCH 100
+ui_touch_t ui_touchrects [ MAXTOUCH ];
+unsigned char ui_touchrect_count = 0;
+
+void ui_register_reset ( void ) {
+  bzero ( ui_touchrects, sizeof(ui_touch_t)*MAXTOUCH );
+  ui_touchrect_count = 0;
+  return;
+}
+
+void ui_register_tab ( unsigned char catnum, unsigned int x, unsigned int y, unsigned int w, unsigned int h ) {
+
+  if ( ui_touchrect_count == MAXTOUCH ) {
+    return;
+  }
+
+  ui_touchrects [ ui_touchrect_count ].r.x = x;
+  ui_touchrects [ ui_touchrect_count ].r.y = y;
+  ui_touchrects [ ui_touchrect_count ].r.w = w;
+  ui_touchrects [ ui_touchrect_count ].r.h = h;
+  ui_touchrects [ ui_touchrect_count ].catnum = catnum;
+  ui_touchrect_count++;
+
+  return;
+}
+
+void ui_register_app ( mm_appref_t *app, unsigned int x, unsigned int y, unsigned int w, unsigned int h ) {
+
+  if ( ui_touchrect_count == MAXTOUCH ) {
+    return;
+  }
+
+  ui_touchrects [ ui_touchrect_count ].r.x = x;
+  ui_touchrects [ ui_touchrect_count ].r.y = y;
+  ui_touchrects [ ui_touchrect_count ].r.w = w;
+  ui_touchrects [ ui_touchrect_count ].r.h = h;
+  ui_touchrects [ ui_touchrect_count ].ref = app;
+  ui_touchrect_count++;
+
+  return;
+}
+
+void ui_touch_act ( unsigned int x, unsigned int y ) {
+
+  unsigned char i;
+  ui_touch_t *t;
+
+  for ( i = 0; i < ui_touchrect_count; i++ ) {
+    t = &(ui_touchrects [ i ]);
+
+    if ( x >= t -> r.x &&
+        x <= t -> r.x + t -> r.w &&
+        y >= t -> r.y &&
+        y <= t -> r.y + t -> r.h
+       )
+    {
+
+      if ( t -> ref ) {
+       ui_selected = t -> ref;
+       ui_push_exec();
+      } else {
+       if ( ui_category != t -> catnum ) {
+         ui_selected = NULL;
+       }
+       ui_category = t -> catnum;
+       render_mask |= CHANGED_CATEGORY;
+      }
+
+      break;
+    }
+
+  } // for
+
+  return;
+}
+
+unsigned char ui_forkexec ( char *argv[] ) {
+  char *fooby = argv[0];
+  int x;
+
+  if ( ( x = fork() ) < 0 ) {
+    pnd_log ( pndn_error, "ERROR: Couldn't fork() for '%s'\n", fooby );
+    return ( 0 );
+  }
+
+  if ( x == 0 ) { // child
+    execv ( fooby, argv );
+    pnd_log ( pndn_error, "ERROR: Couldn't exec(%s)\n", fooby );
+    return ( 0 );
+  }
+
+  // parent, success
+  return ( 1 );
+}
+
+unsigned char ui_threaded_defered_preview ( pnd_disco_t *p ) {
+
+  if ( ! cache_preview ( p, pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 200 ),
+                        pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_height", 180 ) )
+     )
+  {
+    pnd_log ( pndn_debug, "THREAD: Couldn't load preview pic: '%s' -> '%s'\n",
+             IFNULL(p->title_en,"No Name"), p -> preview_pic1 );
+  }
+
+  // trigger that we completed
+  SDL_Event e;
+  bzero ( &e, sizeof(SDL_Event) );
+  e.type = SDL_USEREVENT;
+  e.user.code = sdl_user_finishedpreview;
+  e.user.data1 = p;
+  SDL_PushEvent ( &e );
+
+  return ( 0 );
+}
+
+SDL_Thread *g_icon_thread = NULL;
+void ui_post_scan ( void ) {
+
+  // if deferred icon load, kick off the thread now
+  if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.load_icons_later", 0 ) == 1 ) {
+
+    g_icon_thread = SDL_CreateThread ( (void*)ui_threaded_defered_icon, NULL );
+
+    if ( ! g_icon_thread ) {
+      pnd_log ( pndn_error, "ERROR: Couldn't create icon thread\n" );
+    }
+
+  } // deferred icon load
+
+  return;
+}
+
+unsigned char ui_threaded_defered_icon ( void *p ) {
+  extern pnd_box_handle g_active_apps;
+  pnd_box_handle h = g_active_apps;
+
+  unsigned char maxwidth, maxheight;
+  maxwidth = pnd_conf_get_as_int_d ( g_conf, "grid.icon_max_width", 50 );
+  maxheight = pnd_conf_get_as_int_d ( g_conf, "grid.icon_max_height", 50 );
+
+  pnd_disco_t *iter = pnd_box_get_head ( h );
+
+  while ( iter ) {
+
+    // cache it
+    if ( iter -> pnd_icon_pos &&
+        ! cache_icon ( iter, maxwidth, maxheight ) )
+    {
+      pnd_log ( pndn_warning, "  Couldn't load icon: '%s'\n", IFNULL(iter->title_en,"No Name") );
+    } else {
+
+      // trigger that we completed
+      SDL_Event e;
+      bzero ( &e, sizeof(SDL_Event) );
+      e.type = SDL_USEREVENT;
+      e.user.code = sdl_user_finishedicon;
+      SDL_PushEvent ( &e );
+
+      //pnd_log ( pndn_warning, "  Finished deferred load icon: '%s'\n", IFNULL(iter->title_en,"No Name") );
+      usleep ( pnd_conf_get_as_int_d ( g_conf, "minimenu.defer_icon_us", 50000 ) );
+
+    }
+
+    // next
+    iter = pnd_box_get_next ( iter );
+  } // while
+
+  return ( 0 );
+}
+
+void ui_show_hourglass ( unsigned char updaterect ) {
+
+  SDL_Rect dest;
+  SDL_Surface *s = g_imagecache [ IMG_HOURGLASS ].i;
+
+  dest.x = ( 800 - s -> w ) / 2;
+  dest.y = ( 480 - s -> h ) / 2;
+
+  SDL_BlitSurface ( s, NULL /* whole image */, sdl_realscreen, &dest );
+
+  if ( updaterect ) {
+    SDL_UpdateRects ( sdl_realscreen, 1, &dest );
+  }
+
+  return;
+}
+
+unsigned char ui_pick_skin ( void ) {
+#define MAXSKINS 10
+  char *skins [ MAXSKINS ];
+  unsigned char iter;
+
+  char *searchpath = pnd_conf_get_as_char ( g_conf, "minimenu.skin_searchpath" );
+  char tempname [ 100 ];
+
+  iter = 0;
+
+  skins [ iter++ ] = "No skin change";
+
+  SEARCHPATH_PRE
+  {
+    DIR *d = opendir ( buffer );
+
+    if ( d ) {
+      struct dirent *dd;
+
+      while ( ( dd = readdir ( d ) ) ) {
+
+       if ( dd -> d_name [ 0 ] == '.' ) {
+         // ignore
+       } else if ( ( dd -> d_type == DT_DIR || dd -> d_type == DT_UNKNOWN ) &&
+                   iter < MAXSKINS )
+       {
+         snprintf ( tempname, 100, "Skin: %s", dd -> d_name );
+         skins [ iter++ ] = strdup ( tempname );
+       }
+
+      }
+
+      closedir ( d );
+    }
+
+  }
+  SEARCHPATH_POST
+
+  int sel = ui_modal_single_menu ( skins, iter, "Skins", "Enter to select; other to return." );
+
+  // did they pick one?
+  if ( sel > 0 ) {
+    FILE *f;
+
+    char *s = strdup ( pnd_conf_get_as_char ( g_conf, "minimenu.skin_selected" ) );
+    s = pnd_expand_tilde ( s );
+
+    f = fopen ( s, "w" );
+
+    free ( s );
+
+    if ( f ) {
+      fprintf ( f, "%s\n", skins [ sel ] + 6 );
+      fclose ( f );
+    }
+
+    return ( 1 );
+  }
+
+  return ( 0 );
+}