+
+static char _vbuf [ 512 ];
+unsigned char cat_is_visible ( pnd_conf_handle h, char *catname ) {
+ snprintf ( _vbuf, 500, "tabshow.%s", catname );
+ return ( pnd_conf_get_as_int_d ( g_conf, _vbuf, 1 ) ); // default to 'show' when unknown
+}
+
+unsigned char app_is_visible ( pnd_conf_handle h, char *uniqueid ) {
+ snprintf ( _vbuf, 500, "appshow.%s", uniqueid );
+ return ( pnd_conf_get_as_int_d ( g_conf, _vbuf, 1 ) ); // default to 'show' when unknown
+}
+
+void sigquit_handler ( int n ) {
+ pnd_log ( pndn_rem, "SIGQUIT received; graceful exit.\n" );
+ emit_and_quit ( MM_QUIT );
+}
+
+void setup_notifications ( void ) {
+
+ // figure out notify path
+ char *configpath;
+ char *notifypath = NULL;
+
+ configpath = pnd_conf_query_searchpath();
+
+ pnd_conf_handle apph;
+
+ apph = pnd_conf_fetch_by_id ( pnd_conf_apps, configpath );
+
+ if ( apph ) {
+
+ notifypath = pnd_conf_get_as_char ( apph, PND_APPS_NOTIFY_KEY );
+
+ if ( ! notifypath ) {
+ notifypath = PND_APPS_NOTIFYPATH;
+ }
+
+ }
+
+ // given notify path.. ripped from pndnotifyd :(
+ char *searchpath = notifypath;
+
+ // if this is first time through, we can just set it up; for subsequent times
+ // through, we need to close existing fd and re-open it, since we're too lame
+ // to store the list of watches and 'rm' them
+#if 1
+ if ( nh ) {
+ pnd_notify_shutdown ( nh );
+ nh = 0;
+ }
+#endif
+
+ // set up a new set of notifies
+ if ( ! nh ) {
+ nh = pnd_notify_init();
+ }
+
+ if ( ! nh ) {
+ pnd_log ( pndn_rem, "INOTIFY failed to init.\n" );
+ exit ( -1 );
+ }
+
+#if 0
+ pnd_log ( pndn_rem, "INOTIFY is up.\n" );
+#endif
+
+ SEARCHPATH_PRE
+ {
+
+ pnd_log ( pndn_rem, "Watching path '%s' and its descendents.\n", buffer );
+ pnd_notify_watch_path ( nh, buffer, PND_NOTIFY_RECURSE );
+
+ }
+ SEARCHPATH_POST
+
+ return;
+}
+
+// for Pleng
+// Goal: normally menu will quit when an app is invoked, but there are cases when some folks
+// may configure their system and want mmenu to live instead (save on restart time, don't care
+// about RAM, using a multitasking tray/window manager setup...), so instead of 'exit and emit'
+// here we just run the app directly and cross fingers!
+void emit_and_run ( char *buffer ) {
+
+ // run the bloody thing
+ int f;
+
+ if ( ( f = fork() ) < 0 ) {
+ // error forking
+ } else if ( f > 0 ) {
+ // parent
+ } else {
+ // child, do it
+ execl ( "/bin/sh", "/bin/sh", "-c", buffer + strlen(MM_RUN) + 1, (char*) NULL );
+ }
+
+ return;
+}
+
+// this code was swiped from pnd_utility pnd_exec_no_wait_1 as it became a little too minimenu-specific to remain there
+void exec_raw_binary ( char *fullpath ) {
+ int i;
+
+ if ( ( i = fork() ) < 0 ) {
+ printf ( "ERROR: Couldn't fork()\n" );
+ return;
+ }
+
+ if ( i ) {
+ return; // parent process, don't care
+ }
+
+ // child process, do something
+ execl ( "/bin/sh", "/bin/sh", "-c", fullpath, (char*) NULL );
+ //execl ( fullpath, fullpath, (char*) NULL );
+
+ // error invoking something, and we're the child process, so just die before all hell breaks lose with us thinking we're the (second!) parent on return!
+ exit ( -1 );
+
+ // getting here is an error
+ //printf ( "Error attempting to run %s\n", fullpath );
+
+ return;
+}