This is an automated email from the git hooks/post-receive script.

git pushed a commit to branch master
in repository efm2.

View the commit online.

commit c8059ff179c830fa6d2cbc0af0ed964c2498cdab
Author: Carsten Haitzler (Rasterman) <ras...@rasterman.com>
AuthorDate: Wed May 22 17:36:41 2024 +0100

    have sub opens auto exit properly when idle
---
 src/backends/default/open.c | 61 +++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 56 insertions(+), 5 deletions(-)

diff --git a/src/backends/default/open.c b/src/backends/default/open.c
index 0ea4de8..ecce45d 100644
--- a/src/backends/default/open.c
+++ b/src/backends/default/open.c
@@ -17,7 +17,9 @@
 #include <pwd.h>
 #include <grp.h>
 
+#include "Ecore_Common.h"
 #include "cmd.h"
+#include "eina_types.h"
 #include "sha.h"
 #include "meta.h"
 #include "thumb_check.h"
@@ -26,6 +28,8 @@
 static const char *icon_theme = NULL;
 static const char *config_dir = NULL;
 static const char *home_dir   = NULL;
+static Eina_Bool   auto_exit  = EINA_FALSE;
+static int         child_exes = 0;
 
 static Ecore_File_Monitor *mon = NULL;
 static Eina_Bool           can_write = EINA_FALSE;
@@ -38,6 +42,7 @@ typedef struct
   Ecore_Exe   *exe;
   Ecore_Timer *busy_delay_timer;
 } Thumb;
+
 static Ecore_Event_Handler *thumb_exe_del_handler = NULL;
 static Eina_List           *thumb_queue           = NULL;
 static Eina_List           *thumb_busy_queue      = NULL;
@@ -55,6 +60,41 @@ typedef struct
 
 //static Eina_List *op_queue = NULL;
 
+static Eina_Bool
+_cb_auto_exit_timer(void *data EINA_UNUSED)
+{
+  ecore_main_loop_quit();
+  return EINA_FALSE;
+}
+
+static void
+_handle_exe_del(void)
+{
+  if (child_exes > 0)
+    {
+      child_exes--;
+      if (child_exes <= 0)
+        {
+          if (auto_exit)
+            ecore_timer_add(1.0, _cb_auto_exit_timer, NULL);
+        }
+    }
+}
+
+static Eina_Bool
+_cb_auto_del_timer(void *data EINA_UNUSED)
+{
+  if ((child_exes <= 0) && (auto_exit)) ecore_main_loop_quit();
+  return EINA_FALSE;
+}
+
+static Eina_Bool
+_cb_exe_del(void *data EINA_UNUSED, int ev_type EINA_UNUSED, void *event EINA_UNUSED)
+{
+  _handle_exe_del();
+  return ECORE_CALLBACK_DONE;
+}
+
 typedef struct
 {
   const char          *path;
@@ -126,7 +166,6 @@ _sub_del(Sub *sub)
   ecore_event_handler_del(sub->handler_exe_data);
   EINA_LIST_FREE(sub->cmd_pending, buf) eina_strbuf_free(buf);
   EINA_LIST_FREE(sub->timers, st) _sub_timer_free(st);
-  ecore_exe_free(sub->exe);
   free(sub);  
 }
 
@@ -232,7 +271,6 @@ _cb_sub_exe_del(void *data, int ev_type EINA_UNUSED, void *event)
   Ecore_Exe_Event_Del *ev  = event;
 
   if (sub->exe != ev->exe) return ECORE_CALLBACK_PASS_ON;
-  // XXX: handle anything on sub del
   _sub_del(sub);
   return ECORE_CALLBACK_DONE;
 }
@@ -285,15 +323,18 @@ _sub_open(const char *path, const char *backend)
           eina_strbuf_append(buf, "/open");
         }
     }
+  putenv("EFM_OPEN_AUTOEXIT=1");
   sub->handler_exe_del = ecore_event_handler_add(ECORE_EXE_EVENT_DEL,
                                                  _cb_sub_exe_del, sub);
   sub->handler_exe_data = ecore_event_handler_add(ECORE_EXE_EVENT_DATA,
                                                   _cb_sub_exe_data, sub);
   sub->exe              = ecore_exe_pipe_run(eina_strbuf_string_get(buf),
-                                             ECORE_EXE_PIPE_READ |
-                                             ECORE_EXE_PIPE_READ_LINE_BUFFERED |
-                                             ECORE_EXE_PIPE_WRITE,
+                                             ECORE_EXE_PIPE_READ
+                                             | ECORE_EXE_PIPE_READ_LINE_BUFFERED
+                                             | ECORE_EXE_PIPE_WRITE,
                                              sub);
+  child_exes++;
+
   fprintf(stderr, "SUB %s\n", eina_strbuf_string_get(buf));
   eina_strbuf_free(buf);
   buf = cmd_strbuf_new("dir-set");
@@ -369,6 +410,7 @@ _file_thumb_flush(void)
       eina_strbuf_append_char(strbuf, ' ');
       _strbuf_append_file_escaped(strbuf, th->thumb);
       th->exe = ecore_exe_run(eina_strbuf_string_get(strbuf), th);
+      child_exes++;
     }
   eina_strbuf_free(strbuf);
 }
@@ -1251,6 +1293,7 @@ _op_run(const char *op, Eina_List *files, const char *dst)
   fprintf(stderr, "OP: op [%s]\n", eina_strbuf_string_get(buf));
   exe = ecore_exe_pipe_run(eina_strbuf_string_get(buf), ECORE_EXE_PIPE_WRITE,
                            NULL);
+  child_exes++;
   eina_strbuf_reset(buf);
   EINA_LIST_FOREACH(files, l, s)
   {
@@ -1477,6 +1520,8 @@ do_init(int argc EINA_UNUSED, const char **argv EINA_UNUSED)
       snprintf(buf, sizeof(buf), "%s/.e/e", home_dir);
       config_dir = eina_stringshare_add(buf);
     }
+  s = getenv("EFM_OPEN_AUTOEXIT");
+  if ((s) && (atoi(s) == 1)) auto_exit = EINA_TRUE;
 
   // maximum number of back-end thumbnailer slaves is num_cores - 2
   // with a minimum of 1 (so dual core systems will be limited to 1
@@ -1493,6 +1538,12 @@ do_init(int argc EINA_UNUSED, const char **argv EINA_UNUSED)
   // we want to listen for when thumbnails slaves finish
   thumb_exe_del_handler
     = ecore_event_handler_add(ECORE_EXE_EVENT_DEL, _cb_thumb_exe_del, NULL);
+
+  if (auto_exit)
+    {
+      ecore_event_handler_add(ECORE_EXE_EVENT_DEL, _cb_exe_del, NULL);
+      ecore_timer_add(5.0, _cb_auto_del_timer, NULL);
+    }
   return 0;
 }
 

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.

Reply via email to