Lots of changes/additions for minimenu
authorskeezix <skeezix@flotsam-vm.(none)>
Tue, 9 Mar 2010 21:10:14 +0000 (16:10 -0500)
committerskeezix <skeezix@flotsam-vm.(none)>
Tue, 9 Mar 2010 21:10:14 +0000 (16:10 -0500)
- shows a menu when you hit Start now (so you can shutdown, or chang environments)
Commented out some debugging I'd recently added to libpnd proper

12 files changed:
deployment/etc/pandora/conf/mmenu.conf
include/pnd_locate.h
lib/pnd_discovery.c
lib/pnd_tinyxml.cpp
minimenu/TODO.txt
minimenu/mmenu.c
minimenu/mmenu.conf
minimenu/mmenu.h
minimenu/mmui.c
minimenu/mmui.h
minimenu/mmwrapcmd.h
minimenu/mmwrapper.c

index 46eb120..3dedc2e 100644 (file)
@@ -2,18 +2,19 @@
 #
 
 [minimenu]
-static_art_path                ./minimenu/skin/default
+static_art_searchpath  /etc/pandora/mmenu/skins/default:./minimenu/skin/default
 font                   Vera.ttf
 font_ptsize            24
 pndrun                 /usr/pandora/scripts:./testdata/scripts # searchpath to locate "pnd_run.sh"; why aren't I looking in /etc/pandora/conf/apps for this?
 load_previews_now      0       # if >0, will try to load preview pics from pnds at boot time, not defer till later
-loglevel               3       # 0 is debug, lots of crap; 3 is better, means 'errors only'. Output may screw up the wrapper!
+load_previews_later    0       # if >0, will try to load preview pics sometime (see defer_timer_ms as well)
+loglevel               0       # 0 is debug, lots of crap; 3 is better, means 'errors only'. Output may screw up the wrapper!
 
 [apps]
 searchpath             ./testdata/app2:./testdata/app3:/media/*/pandora/desktop
 
 [display]
-fullscreen             1       # 0 for windowed, >0 for fullscreen
+fullscreen             0       # 0 for windowed, >0 for fullscreen
 screen_width           800     # for some calculations
 detail_bg_alpha                100     # when rendering the detail panel background, how transparent?
 font_rgba_r            220     # RGBA for the display text
@@ -22,6 +23,12 @@ font_rgba_b          220     # RGBA for the display text
 font_rgba_a            20      # RGBA for the display text
 
 [tabs]
+top_maincat            1       # include maincat in top tab bar
+top_maincat1           0       # include maincat subcat 1 in top tab bar
+top_maincat2           0       # include maincat subcat 1 in top tab bar
+top_altcat             1       # include alt cat in top tab bar
+top_altcat1            0       # include alt cat subcat 1 in top tab bar
+top_altcat2            0       # include alt cat subcat 1 in top tab bar
 wraparound             0       # if 1, last tab wraps around to first when going right; going left from first tab goes to last
 font                   Vera.ttf
 font_ptsize            16
@@ -51,7 +58,7 @@ cell_height           92      # cell location is grid_offset_y + ( cell_height * column_number
 col_max                        5       # number of columns to render into grid
 row_max                        4       # number of rows to display before we stop rendering
 text_hilite_offset_y   62      # from top of cell to top of hilight
-scroll_increment       1       # number of rows to scroll when jumping up or down (recommend 1, or same as row_max for full page jump)
+scroll_increment       4       # number of rows to scroll when jumping up or down (recommend 1, or same as row_max for full page jump)
 arrow_up_x             450     # left edge of up-arrow showing more icons scrolled away
 arrow_up_y             80      # top edge of up-arrow showing more icons scrolled away
 arrow_down_x           450     # left edge of down-arrow showing more icons scrolled away
@@ -74,6 +81,7 @@ cell_offset_y         312     # top edge of text cell
 cell_width             250     # width of cell (for text clipping)
 
 [previewpic]
+defer_timer_ms         1000    # after setting selection, how long to wait before we try to load the previewpic
 cell_offset_x          480     # left edge of text cell
 cell_offset_y          90      # top edge of text cell
 cell_width             285
index 884fd2e..0fa7f02 100644 (file)
@@ -8,6 +8,7 @@ extern "C" {
 
 // given a filename and a searchpath, return the first path it is found at (or NULL if not found)
 // Returned path includes filename.
+// WARNING: Returned path will be over-written, you must duplicate it!
 char *pnd_locate_filename ( char *searchpath, char *filename );
 
 #ifdef __cplusplus
index 4087086..a15ef27 100644 (file)
@@ -183,7 +183,7 @@ static int pnd_disco_callback ( const char *fpath, const struct stat *sb,
       char *fixpxml;
       char *z;
 
-      pnd_log ( PND_LOG_DEFAULT, "Setting up discovered app %u\n", ((pnd_pxml_t*) pxmlh) -> subapp_number );
+      //pnd_log ( PND_LOG_DEFAULT, "Setting up discovered app %u\n", ((pnd_pxml_t*) pxmlh) -> subapp_number );
 
       p = pnd_box_allocinsert ( disco_box, (char*) fpath, sizeof(pnd_disco_t) );
 
index 0e05ad0..da4f13a 100644 (file)
@@ -53,7 +53,7 @@ unsigned char pnd_pxml_parse_titles(const TiXmlHandle hRoot, pnd_pxml_t *app) {
     title->language = lang;
     title->string = text;
 
-    pnd_log ( PND_LOG_DEFAULT, (char*)"    Title/Lang: %s/%s\n", text, lang );
+    //pnd_log ( PND_LOG_DEFAULT, (char*)"    Title/Lang: %s/%s\n", text, lang );
 
   }
 
@@ -140,7 +140,7 @@ unsigned char pnd_pxml_parse ( const char *pFilename, char *buffer, unsigned int
   // until we run out of applications in the PXML..
   while ( 1 ) {
 
-    pnd_log ( PND_LOG_DEFAULT, (char*)"  App #%u inside of PXML %s\n", appcount, pFilename );
+    //pnd_log ( PND_LOG_DEFAULT, (char*)"  App #%u inside of PXML %s\n", appcount, pFilename );
 
     // create the buffer to hold the pxml
     apps [ appcount ] = (pnd_pxml_t*) malloc ( sizeof(pnd_pxml_t) );
@@ -157,10 +157,10 @@ unsigned char pnd_pxml_parse ( const char *pFilename, char *buffer, unsigned int
     //Get unique ID first.
     if ( appwrappermode ) {
       app->unique_id = pnd_pxml_get_attribute(appElem, PND_PXML_ATTRNAME_UID);
-      pnd_log ( PND_LOG_DEFAULT, (char*)"  Subapp #%u has unique_id %s\n", appcount, app -> unique_id );
+      //pnd_log ( PND_LOG_DEFAULT, (char*)"  Subapp #%u has unique_id %s\n", appcount, app -> unique_id );
     } else {
       app->unique_id = pnd_pxml_get_attribute(hRoot.Element(), PND_PXML_ATTRNAME_UID);
-      pnd_log ( PND_LOG_DEFAULT, (char*)"  Only-app #%u has unique_id %s\n", appcount, app -> unique_id );
+      //pnd_log ( PND_LOG_DEFAULT, (char*)"  Only-app #%u has unique_id %s\n", appcount, app -> unique_id );
     }
 
     //Everything related to the title:
@@ -373,7 +373,7 @@ unsigned char pnd_pxml_parse ( const char *pFilename, char *buffer, unsigned int
     if ( appwrappermode ) {
       appElem = appElem -> NextSiblingElement ( PND_PXML_APP );
       if ( ! appElem ) {
-       pnd_log ( PND_LOG_DEFAULT, (char*)"  No more applications within PXML\n" );
+       //pnd_log ( PND_LOG_DEFAULT, (char*)"  No more applications within PXML\n" );
        break; // no more applications
       }
       // got another application..
index d652ea4..baca038 100644 (file)
@@ -5,33 +5,23 @@
 
 - libpnd: appdata-dir-name
 
-- menu
-  - zotmenu?
-  - rescan
-  - shutdown
-  - quit
+- wrapper black screen?
 
-- defer preview pics
+- manual app rescan
 
 - deploy..
   - .desktop for deply
   - tell ED how to launch it
 
-- display
-  - preview pics
-  - battery indicator?
-  - status-line at bottom; number of categories, humber of apps found...?
-  - menu hint text (hit "menu")
-
 - touchscreen
   - launch apps
   - pick/rotate category
 
 - honor render_mask to know what to update
-- defer icon or preview-pics
+- figure out why deferred preview pics blow up
+- handle SD eject/insert
 
 - future
-  - make mmwrapper take all input and..
-    - make the commanbd line have unique token up front ("--->"), so that the command can be found in the mess anyway?
+  - defer icon load?
   - add callback to pnd_disco_Search (maybe new func to not break cpas code), so can show number apps found so far
   - note taking field
index 96b5c3d..6ff5bab 100644 (file)
@@ -56,6 +56,7 @@ char g_username [ 128 ]; // since we have to wait for login (!!), store username
 pnd_conf_handle g_conf = 0;
 
 char *pnd_run_script = NULL;
+char *g_skinpath = NULL;
 
 int main ( int argc, char *argv[] ) {
   int logall = -1; // -1 means normal logging rules; >=0 means log all!
@@ -167,6 +168,33 @@ int main ( int argc, char *argv[] ) {
     emit_and_quit ( MM_QUIT );
   }
 
+  pnd_run_script = strdup ( pnd_run_script ); // so we don't lose it next pnd_locate
+
+  pnd_log ( pndn_rem, "Found pnd_run.sh at '%s'\n", pnd_run_script );
+
+  // figure out skin path
+  if ( ! pnd_conf_get_as_char ( g_conf, MMENU_ARTPATH ) ||
+       ! pnd_conf_get_as_char ( g_conf, "minimenu.font" )
+     )
+  {
+    pnd_log ( pndn_error, "ERROR: Couldn't set up skin!\n" );
+    emit_and_quit ( MM_QUIT );
+  }
+
+  g_skinpath = pnd_locate_filename ( pnd_conf_get_as_char ( g_conf, MMENU_ARTPATH ),
+                                    pnd_conf_get_as_char ( g_conf, "minimenu.font" ) );
+
+  if ( ! g_skinpath ) {
+    pnd_log ( pndn_error, "ERROR: Couldn't locate skin font!\n" );
+    emit_and_quit ( MM_QUIT );
+  }
+
+  g_skinpath = strdup ( g_skinpath ); // so we don't lose it next pnd_locate
+
+  * strstr ( g_skinpath, pnd_conf_get_as_char ( g_conf, "minimenu.font" ) ) = '\0';
+
+  pnd_log ( pndn_debug, "Looks like skin is at '%s'\n", g_skinpath );
+
   // attempt to set up UI
   if ( ! ui_setup() ) {
     pnd_log ( pndn_error, "ERROR: Couldn't set up the UI!\n" );
@@ -177,7 +205,7 @@ int main ( int argc, char *argv[] ) {
   ui_loadscreen();
 
   // set up static image cache
-  if ( ! ui_imagecache ( pnd_conf_get_as_char ( g_conf, MMENU_ARTPATH ) ) ) {
+  if ( ! ui_imagecache ( g_skinpath ) ) {
     pnd_log ( pndn_error, "ERROR: Couldn't set up static UI image cache!\n" );
     emit_and_quit ( MM_QUIT );
   }
index 267faef..77571b7 100644 (file)
@@ -2,11 +2,12 @@
 #
 
 [minimenu]
-static_art_path                ./minimenu/skin/default
+static_art_searchpath  /etc/pandora/mmenu/skins/default:./minimenu/skin/default
 font                   Vera.ttf
 font_ptsize            24
 pndrun                 /usr/pandora/scripts:./testdata/scripts # searchpath to locate "pnd_run.sh"; why aren't I looking in /etc/pandora/conf/apps for this?
 load_previews_now      0       # if >0, will try to load preview pics from pnds at boot time, not defer till later
+load_previews_later    0       # if >0, will try to load preview pics sometime (see defer_timer_ms as well)
 loglevel               0       # 0 is debug, lots of crap; 3 is better, means 'errors only'. Output may screw up the wrapper!
 
 [apps]
@@ -20,6 +21,11 @@ font_rgba_r          220     # RGBA for the display text
 font_rgba_g            220     # RGBA for the display text
 font_rgba_b            220     # RGBA for the display text
 font_rgba_a            20      # RGBA for the display text
+battery_x              10      # (x,y) for battery level
+battery_y              450     # (x,y) for battery level
+hintline               Push START for shutdown options # shown at bottom of screen
+hint_x                 300     # (x,y) for hint line
+hint_y                 450     # (x,y) for hint line
 
 [tabs]
 top_maincat            1       # include maincat in top tab bar
@@ -80,6 +86,7 @@ cell_offset_y         312     # top edge of text cell
 cell_width             250     # width of cell (for text clipping)
 
 [previewpic]
+defer_timer_ms         1000    # after setting selection, how long to wait before we try to load the previewpic
 cell_offset_x          480     # left edge of text cell
 cell_offset_y          90      # top edge of text cell
 cell_width             285
index a271891..0b688a7 100644 (file)
@@ -5,13 +5,14 @@
 // utility
 #define IFNULL(foo,bar) (foo)?(foo):(bar)
 extern char *pnd_run_script;
+extern char *g_skinpath;
 
 // base searchpath to locate the conf
 #define MMENU_CONF "mmenu.conf"
 #define MMENU_CONF_SEARCHPATH "/etc/pandora/conf:./minimenu"
 
 // keys
-#define MMENU_ARTPATH "minimenu.static_art_path"
+#define MMENU_ARTPATH "minimenu.static_art_searchpath"
 #define MMENU_APP_SEARCHPATH "apps.searchpath"
 
 #define MMENU_GRID_FONT "grid.font"
index 40da1cd..eecef61 100644 (file)
@@ -15,6 +15,7 @@
 #include "pnd_container.h"
 #include "pnd_discovery.h"
 #include "pnd_apps.h"
+#include "pnd_device.h"
 
 #include "mmenu.h"
 #include "mmcat.h"
@@ -53,11 +54,6 @@ extern unsigned char g_categorycount;
 static SDL_Surface *ui_scale_image ( SDL_Surface *s, unsigned int maxwidth, int maxheight ); // height -1 means ignore
 static int ui_selected_index ( void );
 
-static unsigned int ui_timer ( unsigned int interval ) {
-  sdl_ticks++;
-  return ( interval );
-}
-
 unsigned char ui_setup ( void ) {
 
   /* set up SDL
@@ -65,8 +61,6 @@ unsigned char ui_setup ( void ) {
 
   SDL_Init ( SDL_INIT_EVERYTHING | SDL_INIT_NOPARACHUTE );
 
-  SDL_SetTimer ( 30, ui_timer ); // 30fps
-
   SDL_JoystickOpen ( 0 ); // turn on joy-0
 
   SDL_WM_SetCaption ( "mmenu", "mmenu" );
@@ -135,7 +129,7 @@ unsigned char ui_setup ( void ) {
 
   char fullpath [ PATH_MAX ];
   // big font
-  sprintf ( fullpath, "%s/%s", pnd_conf_get_as_char ( g_conf, MMENU_ARTPATH ), pnd_conf_get_as_char ( g_conf, "minimenu.font" ) );
+  sprintf ( fullpath, "%s/%s", g_skinpath, pnd_conf_get_as_char ( g_conf, "minimenu.font" ) );
   g_big_font = TTF_OpenFont ( fullpath, pnd_conf_get_as_int_d ( g_conf, "minimenu.font_ptsize", 24 ) );
   if ( ! g_big_font ) {
     pnd_log ( pndn_error, "ERROR: Couldn't load font '%s' for size %u\n",
@@ -144,7 +138,7 @@ unsigned char ui_setup ( void ) {
   }
 
   // grid font
-  sprintf ( fullpath, "%s/%s", pnd_conf_get_as_char ( g_conf, MMENU_ARTPATH ), pnd_conf_get_as_char ( g_conf, MMENU_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 ) );
   if ( ! g_grid_font ) {
     pnd_log ( pndn_error, "ERROR: Couldn't load font '%s' for size %u\n",
@@ -153,7 +147,7 @@ unsigned char ui_setup ( void ) {
   }
 
   // detailtext font
-  sprintf ( fullpath, "%s/%s", pnd_conf_get_as_char ( g_conf, MMENU_ARTPATH ), pnd_conf_get_as_char ( g_conf, "detailtext.font" ) );
+  sprintf ( fullpath, "%s/%s", g_skinpath, pnd_conf_get_as_char ( g_conf, "detailtext.font" ) );
   g_detailtext_font = TTF_OpenFont ( fullpath, pnd_conf_get_as_int_d ( g_conf, "detailtext.font_ptsize", 10 ) );
   if ( ! g_detailtext_font ) {
     pnd_log ( pndn_error, "ERROR: Couldn't load font '%s' for size %u\n",
@@ -162,7 +156,7 @@ unsigned char ui_setup ( void ) {
   }
 
   // tab font
-  sprintf ( fullpath, "%s/%s", pnd_conf_get_as_char ( g_conf, MMENU_ARTPATH ), pnd_conf_get_as_char ( g_conf, "tabs.font" ) );
+  sprintf ( fullpath, "%s/%s", g_skinpath, pnd_conf_get_as_char ( g_conf, "tabs.font" ) );
   g_tab_font = TTF_OpenFont ( fullpath, pnd_conf_get_as_int_d ( g_conf, "tabs.font_ptsize", 10 ) );
   if ( ! g_tab_font ) {
     pnd_log ( pndn_error, "ERROR: Couldn't load font '%s' for size %u\n",
@@ -388,7 +382,7 @@ void ui_render ( unsigned int render_mask ) {
       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_UpdateRects ( sdl_realscreen, 1, &dest );
+      SDL_FreeSurface ( rtext );
       dest++;
 
     } // for
@@ -534,7 +528,7 @@ void ui_render ( unsigned int render_mask ) {
            }
            dest -> y = grid_offset_y + ( displayrow * cell_height ) + text_offset_y;
            SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
-           //SDL_UpdateRects ( sdl_realscreen, 1, &dest );
+           SDL_FreeSurface ( rtext );
            dest++;
          }
 
@@ -586,7 +580,7 @@ void ui_render ( unsigned int render_mask ) {
       dest -> x = cell_offset_x;
       dest -> y = desty;
       SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
-      //SDL_UpdateRects ( sdl_realscreen, 1, &dest );
+      SDL_FreeSurface ( rtext );
       dest++;
       desty += src.h;
     }
@@ -606,7 +600,7 @@ void ui_render ( unsigned int render_mask ) {
       dest -> x = cell_offset_x;
       dest -> y = desty;
       SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
-      //SDL_UpdateRects ( sdl_realscreen, 1, &dest );
+      SDL_FreeSurface ( rtext );
       dest++;
       desty += src.h;
     }
@@ -626,7 +620,7 @@ void ui_render ( unsigned int render_mask ) {
       dest -> x = cell_offset_x;
       dest -> y = desty;
       SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
-      //SDL_UpdateRects ( sdl_realscreen, 1, &dest );
+      SDL_FreeSurface ( rtext );
       dest++;
       desty += src.h;
     }
@@ -652,6 +646,39 @@ void ui_render ( unsigned int render_mask ) {
 
   } // selected?
 
+  // extras
+  //
+
+  // battery
+  if ( 1 ) {
+    unsigned char batterylevel = pnd_device_get_battery_gauge_perc();
+    char buffer [ 100 ];
+
+    sprintf ( buffer, "Battery: %u%%", batterylevel );
+
+    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.battery_x", 20 );
+    dest -> y = pnd_conf_get_as_int_d ( g_conf, "display.battery_y", 450 );
+    SDL_BlitSurface ( rtext, NULL /* all */, sdl_realscreen, dest );
+    SDL_FreeSurface ( rtext );
+    dest++;
+  }
+
+  // hints
+  if ( pnd_conf_get_as_char ( g_conf, "display.hintline" ) ) {
+    char *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 );
+    SDL_BlitSurface ( rtext, NULL /* all */, sdl_realscreen, dest );
+    SDL_FreeSurface ( rtext );
+    dest++;
+  }
+
   // update all the rects and send it all to sdl
   SDL_UpdateRects ( sdl_realscreen, dest - rects, rects );
 
@@ -669,6 +696,29 @@ void ui_process_input ( unsigned char block_p ) {
 
     switch ( event.type ) {
 
+    case SDL_USEREVENT:
+      // update something
+
+      if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.load_previews_later", 0 ) ) {
+
+       pnd_log ( pndn_debug, "Deferred preview pic load ----------\n" );
+
+       // 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 );
+       }
+
+       pnd_log ( pndn_debug, "Deferred preview pic load finish ---\n" );
+
+       ui_event++;
+      }
+
+      break;
+
 #if 0 // joystick motion
     case SDL_JOYAXISMOTION:
 
@@ -765,6 +815,8 @@ void ui_process_input ( unsigned char block_p ) {
 
       //pnd_log ( pndn_debug, "key up %u\n", event.key.keysym.sym );
 
+      // SDLK_LALT -> Start
+
       // directional
       if ( event.key.keysym.sym == SDLK_RIGHT ) {
        ui_push_right();
@@ -787,6 +839,43 @@ 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_LALT ) { // start button
+       char *opts [ 10 ] = {
+         "Return to Minimenu",
+         "Shutdown Pandora",
+         "Rescan for Applications",
+         "Set to full desktop and reboot",
+         "Set to pmenu and reboot",
+         "Quit (<- beware)"
+       };
+       int sel = ui_modal_single_menu ( opts, 6, "Minimenu", "Enter to select; other to return." );
+
+       char buffer [ 100 ];
+       if ( sel == 0 ) {
+         return ( -1 ); // return
+       } else if ( sel == 1 ) {
+         sprintf ( buffer, "sudo poweroff" );
+         system ( buffer );
+       } else if ( sel == 2 ) {
+         // rescan apps
+       } else if ( sel == 3 ) {
+         // set env to xfce
+         sprintf ( buffer, "echo startxfce4 > /tmp/gui.load" );
+         system ( buffer );
+         sprintf ( buffer, "sudo poweroff" );
+         system ( buffer );
+       } else if ( sel == 4 ) {
+         // set env to pmenu
+         sprintf ( buffer, "echo pmenu > /tmp/gui.load" );
+         system ( buffer );
+         sprintf ( buffer, "sudo poweroff" );
+         system ( buffer );
+       } else if ( sel == 5 ) {
+         emit_and_quit ( MM_QUIT );
+       }
+
+       ui_event++;
       }
 
       // extras
@@ -850,6 +939,8 @@ void ui_push_left ( void ) {
     }
   }
 
+  ui_set_selected ( ui_selected );
+
   return;
 }
 
@@ -865,6 +956,8 @@ void ui_push_right ( void ) {
     ui_selected = g_categories [ ui_category ].refs;
   }
 
+  ui_set_selected ( ui_selected );
+
   return;
 }
 
@@ -927,6 +1020,7 @@ void ui_push_ltrigger ( void ) {
 
   if ( oldcat != ui_category ) {
     ui_selected = NULL;
+    ui_set_selected ( ui_selected );
   }
 
   // make tab visible?
@@ -956,6 +1050,7 @@ void ui_push_rtrigger ( void ) {
 
   if ( oldcat != ui_category ) {
     ui_selected = NULL;
+    ui_set_selected ( ui_selected );
   }
 
   // make tab visible?
@@ -1018,6 +1113,7 @@ void ui_loadscreen ( void ) {
   dest.y = 20;
   SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, &dest );
   SDL_UpdateRects ( sdl_realscreen, 1, &dest );
+  SDL_FreeSurface ( rtext );
 
   return;
 }
@@ -1060,6 +1156,7 @@ void ui_discoverscreen ( unsigned char clearscreen ) {
   }
   SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, &dest );
   SDL_UpdateRects ( sdl_realscreen, 1, &dest );
+  SDL_FreeSurface ( rtext );
 
   // render icon
   if ( g_imagecache [ IMG_ICON_MISSING ].i ) {
@@ -1113,6 +1210,7 @@ void ui_cachescreen ( unsigned char clearscreen, char *filename ) {
     dest -> y = 40;
   }
   SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
+  SDL_FreeSurface ( rtext );
   dest++;
 
   // render icon
@@ -1129,6 +1227,7 @@ void ui_cachescreen ( unsigned char clearscreen, char *filename ) {
     dest -> x = 20;
     dest -> y = 50;
     SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
+    SDL_FreeSurface ( rtext );
     dest++;
   }
 
@@ -1162,3 +1261,173 @@ int ui_selected_index ( void ) {
 
   return ( -1 );
 }
+
+static mm_appref_t *timer_ref = NULL;
+void ui_set_selected ( mm_appref_t *r ) {
+
+  if ( ! pnd_conf_get_as_int_d ( g_conf, "minimenu.load_previews_later", 0 ) ) {
+    return; // no desire to defer anything
+  }
+
+  if ( ! r ) {
+    // cancel timer
+    SDL_SetTimer ( 0, NULL );
+    timer_ref = NULL;
+    return;
+  }
+
+  SDL_SetTimer ( pnd_conf_get_as_int_d ( g_conf, "previewpic.defer_timer_ms", 1000 ), ui_callback_f );
+  timer_ref = r;
+
+  return;
+}
+
+unsigned int ui_callback_f ( unsigned int t ) {
+
+  if ( ui_selected != timer_ref ) {
+    return ( 0 ); // user has moved it, who cares
+  }
+
+  SDL_Event e;
+  e.type = SDL_USEREVENT;
+  SDL_PushEvent ( &e );
+
+  return ( 0 );
+}
+
+int ui_modal_single_menu ( char *argv[], unsigned int argc, char *title, char *footer ) {
+  SDL_Rect rects [ 40 ];
+  SDL_Rect *dest = rects;
+  SDL_Rect src;
+  SDL_Surface *rtext;
+
+  bzero ( rects, sizeof(SDL_Rect) * 40 );
+
+  unsigned int sel = 0;
+
+  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 );
+  unsigned int font_rgba_b = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_b", 200 );
+  unsigned int font_rgba_a = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_a", 100 );
+
+  SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
+
+  SDL_Color selfontcolor = { 0/*font_rgba_r*/, font_rgba_g, font_rgba_b, font_rgba_a };
+
+  unsigned int i;
+  SDL_Event event;
+
+  while ( 1 ) {
+
+    // clear
+    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 );
+    dest -> w = ((SDL_Surface*) g_imagecache [ IMG_DETAIL_PANEL ].i) -> w;
+    dest -> h = ((SDL_Surface*) g_imagecache [ IMG_DETAIL_PANEL ].i) -> h;
+    SDL_FillRect( sdl_realscreen, dest, 0 );
+
+    // show dialog background
+    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 );
+      // repeat for darken?
+      SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
+      SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
+      //SDL_UpdateRects ( sdl_realscreen, 1, &dest );
+      dest++;
+    }
+
+    // show dialog frame
+    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++;
+    }
+
+    // show header
+    if ( title ) {
+      rtext = TTF_RenderText_Blended ( g_tab_font, title, tmpfontcolor );
+      dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 ) + 20;
+      dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 ) + 20;
+      SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
+      SDL_FreeSurface ( rtext );
+      dest++;
+    }
+
+    // show footer
+    if ( footer ) {
+      rtext = TTF_RenderText_Blended ( g_tab_font, footer, tmpfontcolor );
+      dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 ) + 20;
+      dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 ) +
+       ((SDL_Surface*) g_imagecache [ IMG_DETAIL_PANEL ].i) -> h
+       - 60;
+      SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
+      SDL_FreeSurface ( rtext );
+      dest++;
+    }
+
+    // show options
+    for ( i = 0; i < argc; i++ ) {
+
+      // show options
+      if ( sel == i ) {
+       rtext = TTF_RenderText_Blended ( g_tab_font, argv [ i ], selfontcolor );
+      } else {
+       rtext = TTF_RenderText_Blended ( g_tab_font, argv [ i ], tmpfontcolor );
+      }
+      dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 ) + 20;
+      dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 ) + 40 + ( 20 * ( i + 1 ) );
+      SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
+      SDL_FreeSurface ( rtext );
+      dest++;
+
+    } // for
+
+    // update all the rects and send it all to sdl
+    SDL_UpdateRects ( sdl_realscreen, dest - rects, rects );
+    dest = rects;
+
+    // check for input
+    while ( SDL_WaitEvent ( &event ) ) {
+
+      switch ( event.type ) {
+
+      case SDL_KEYUP:
+
+       if ( event.key.keysym.sym == SDLK_UP ) {
+         if ( sel ) {
+           sel--;
+         }
+       } else if ( event.key.keysym.sym == SDLK_DOWN ) {
+         if ( sel < argc - 1 ) {
+           sel++;
+         }
+
+       } else if ( event.key.keysym.sym == SDLK_RETURN ) {
+         return ( sel );
+
+       } else if ( event.key.keysym.sym == SDLK_q ) {
+         exit ( 0 );
+
+       } else {
+         return ( -1 ); // nada
+       }
+
+       break;
+
+      } // switch
+
+      break;
+    } // while
+
+  } // while
+
+  return ( -1 );
+}
index ec9ce6c..10a9984 100644 (file)
@@ -65,6 +65,9 @@ void ui_loadscreen ( void );        // show screen while loading the menu
 void ui_discoverscreen ( unsigned char clearscreen ); // screen to show while scanning for apps
 void ui_cachescreen ( unsigned char clearscreen, char *filename ); // while caching icons, categories and preview-pics-Now-mode
 
+// show a menu, return when selection made; -1 means no selection. Enter is pick.
+int ui_modal_single_menu ( char *argv[], unsigned int argc, char *title, char *footer );
+
 /* internal functions follow
  */
 
@@ -83,4 +86,8 @@ void ui_register_reset ( void );
 void ui_register_tab ( mm_category_t *category, unsigned int x, unsigned int y, unsigned int w, unsigned int h );
 void ui_register_app ( pnd_disco_t *app, unsigned int x, unsigned int y, unsigned int w, unsigned int h );
 
+// deferred preview timer
+void ui_set_selected ( mm_appref_t *r );
+unsigned int ui_callback_f ( unsigned int t );
+
 #endif
index 6f8580b..ca21479 100644 (file)
@@ -4,7 +4,9 @@
 
 // since only like 2 or 3 commands, no need for enum's/etc
 
-#define MM_QUIT "quit"
-#define MM_RUN "run"
+#define MM_WATCHIT "--->"
+
+#define MM_QUIT "--->quit"
+#define MM_RUN "--->run"
 
 #endif
index 7ca7949..63749f1 100644 (file)
@@ -180,7 +180,12 @@ int main ( int argc, char *argv[] ) {
     pnd_log ( pndn_debug, "Invoking frontend: %s\n", g_frontend );
 
     FILE *fe = popen ( g_frontend, "r" );
-    fgets ( cmdbuf, 1000, fe );
+    while ( fgets ( cmdbuf, 1000, fe ) ) {
+      if ( strstr ( cmdbuf, MM_WATCHIT ) ) {
+       break;
+      }
+      pnd_log ( pndn_debug, "Junk: %s", cmdbuf );
+    }
     pclose ( fe );
 
     if ( ( c = strchr ( cmdbuf, '\n' ) ) ) {