Juggled timers around; now can sit at 'idle' and eating only 3-4% of cpu. Should...
authorskeezix <skeezix@flotsam-vm.(none)>
Mon, 31 Jan 2011 21:29:30 +0000 (16:29 -0500)
committerskeezix <skeezix@flotsam-vm.(none)>
Mon, 31 Jan 2011 21:29:30 +0000 (16:29 -0500)
minimenu/mmcache.c
minimenu/mmconf.c
minimenu/mmenu.c
minimenu/mmui.c
minimenu/mmui.h

index 691a2cc..4f68f36 100644 (file)
@@ -31,6 +31,8 @@
 #include "pnd_apps.h"
 #include "../lib/pnd_pathiter.h"
 #include "pnd_locate.h"
+#include "pnd_notify.h"
+#include "pnd_dbusnotify.h"
 
 #include "mmenu.h"
 #include "mmapps.h"
index c77bc11..b67b834 100644 (file)
@@ -11,6 +11,8 @@
 #include "pnd_container.h"
 #include "pnd_conf.h"
 #include "pnd_discovery.h"
+#include "pnd_notify.h"
+#include "pnd_dbusnotify.h"
 
 #include "mmenu.h"
 #include "mmconf.h"
index 02fe2a1..3cb5d18 100644 (file)
@@ -373,16 +373,16 @@ int main ( int argc, char *argv[] ) {
 
   /* actual work now
    */
-  unsigned char block = 1;
-
   if ( g_autorescan ) {
-    block = 0;
 
     // set up notifications
     dbh = pnd_dbusnotify_init();
     pnd_log ( pndn_debug, "Setting up dbusnotify\n" );
     //setup_notifications();
 
+    // create a timer thread, that will trigger us to check for SD insert notifications every once in awhile
+    ui_threaded_timer_create();
+
   } // set up rescan
 
   /* set speed to minimenu run-speed, now that we're all set up
@@ -405,33 +405,8 @@ int main ( int argc, char *argv[] ) {
     // show the menu, or changes thereof
     ui_render();
 
-    // wait for input or time-based events (like animations)
-    // deal with inputs
-    ui_process_input ( block /* block */ );
-
-    // did a rescan event trigger?
-    if ( g_autorescan ) {
-      unsigned char watch_dbus = 0;
-      unsigned char watch_inotify = 0;
-
-      if ( dbh ) {
-       watch_dbus = pnd_dbusnotify_rediscover_p ( dbh );
-      }
-
-      if ( nh ) {
-       watch_inotify = pnd_notify_rediscover_p ( nh );
-      }
-
-      if ( watch_dbus || watch_inotify ) {
-       pnd_log ( pndn_debug, "dbusnotify detected SD event\n" );
-       applications_free();
-       applications_scan();
-      }
-
-    } // rescan?
-
-    // sleep? block?
-    usleep ( 100000 /*5000*/ );
+    // wait for input or time-based events (like animations) and deal with inputs
+    ui_process_input ( dbh, nh );
 
   } // while
 
index 15b02cc..f04a31b 100644 (file)
@@ -28,6 +28,8 @@
 #include "../lib/pnd_pathiter.h"
 #include "pnd_utility.h"
 #include "pnd_pndfiles.h"
+#include "pnd_notify.h"
+#include "pnd_dbusnotify.h"
 
 #include "mmenu.h"
 #include "mmcat.h"
@@ -52,10 +54,12 @@ unsigned int render_mask = CHANGED_EVERYTHING;
 SDL_Surface *sdl_realscreen = NULL;
 unsigned int sdl_ticks = 0;
 SDL_Thread *g_preview_thread = NULL;
+SDL_Thread *g_timer_thread = NULL;
 
 enum { sdl_user_ticker = 0,
        sdl_user_finishedpreview = 1,
        sdl_user_finishedicon = 2,
+       sdl_user_checksd = 3,
 };
 
 /* app state
@@ -1029,14 +1033,14 @@ void ui_render ( void ) {
 
 } // ui_render
 
-void ui_process_input ( unsigned char block_p ) {
+void ui_process_input ( pnd_dbusnotify_handle dbh, pnd_notify_handle nh ) {
   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
 
-  while ( ! ui_event &&
-         block_p ? SDL_WaitEvent ( &event ) : SDL_PollEvent ( &event ) )
+  while ( ( ! ui_event ) &&
+         /*block_p ?*/ SDL_WaitEvent ( &event ) /*: SDL_PollEvent ( &event )*/ )
   {
 
     switch ( event.type ) {
@@ -1105,7 +1109,29 @@ void ui_process_input ( unsigned char block_p ) {
        // redraw, so we can show the newly loaded icon
        ui_event++;
 
-      }
+      } else if ( event.user.code == sdl_user_checksd ) {
+       // check if any inotify-type events occured, forcing us to rescan/re-disco the SDs
+
+       unsigned char watch_dbus = 0;
+       unsigned char watch_inotify = 0;
+
+       if ( dbh ) {
+         watch_dbus = pnd_dbusnotify_rediscover_p ( dbh );
+       }
+
+       if ( nh ) {
+         watch_inotify = pnd_notify_rediscover_p ( nh );
+       }
+
+       if ( watch_dbus || watch_inotify ) {
+         pnd_log ( pndn_debug, "dbusnotify detected SD event\n" );
+         applications_free();
+         applications_scan();
+
+         ui_event++;
+       }
+
+      } // SDL user event
 
       render_mask |= CHANGED_EVERYTHING;
 
@@ -2544,6 +2570,44 @@ unsigned char ui_forkexec ( char *argv[] ) {
   return ( 1 );
 }
 
+unsigned char ui_threaded_timer_create ( void ) {
+
+  g_timer_thread = SDL_CreateThread ( (void*)ui_threaded_timer, NULL );
+
+  if ( ! g_timer_thread ) {
+    pnd_log ( pndn_error, "ERROR: Couldn't create timer thread\n" );
+    return ( 0 );
+  }
+
+  return ( 1 );
+}
+
+int ui_threaded_timer ( pnd_disco_t *p ) {
+
+  // this timer's job is to ..
+  // - do nothing for quite awhile
+  // - on wake, post event to SDL event queue, so that main thread will check if SD insert/eject occurred
+  // - goto 10
+
+  unsigned int delay_s = 2; // seconds
+
+  while ( 1 ) {
+
+    // pause...
+    sleep ( delay_s );
+
+    // .. trigger SD check
+    SDL_Event e;
+    bzero ( &e, sizeof(SDL_Event) );
+    e.type = SDL_USEREVENT;
+    e.user.code = sdl_user_checksd;
+    SDL_PushEvent ( &e );
+
+  } // while
+
+  return ( 0 );
+}
+
 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 ),
index 96a9918..7ba395c 100644 (file)
@@ -85,11 +85,13 @@ int ui_modal_single_menu ( char *argv[], unsigned int argc, char *title, char *f
 unsigned char ui_forkexec ( char *argv[] ); // argv[0] is proggy to exec; argv last entry must be NULLptr
 
 // create a thread of this guy, and it'll try to load the preview pic in background and then signal the app
-unsigned char ui_threaded_defered_preview ( pnd_disco_t *p );
-unsigned char ui_threaded_defered_icon ( void * );
+unsigned char ui_threaded_defered_preview ( pnd_disco_t *p ); // callback
+unsigned char ui_threaded_defered_icon ( void * ); // callback
+unsigned char ui_threaded_timer_create ( void );
+int ui_threaded_timer ( pnd_disco_t *p ); // callback
 
 // change the focus
-void ui_process_input ( unsigned char block_p );
+void ui_process_input ( pnd_dbusnotify_handle dbh, pnd_notify_handle nh );
 void ui_push_left ( unsigned char forcecoil );
 void ui_push_right ( unsigned char forcecoil );
 void ui_push_up ( void );