2 #include "e_actions_intern.h"
3 #include "e_test_helper_intern.h"
4 #include "e_user_intern.h"
5 #include "e_utils_intern.h"
8 # include <sys/prctl.h>
11 # include <systemd/sd-daemon.h>
20 t1 = ecore_time_unix_get(); \
21 printf("ESTART: %1.5f [%1.5f] - %s\n", t1 - t0, t1 - t2, x); \
27 TRACE_DS_BEGIN(ESTART: %s, x); \
37 TRACE_DS_MARK(ESTART: %s, x); \
40 static double t0, t1, t2;
48 * i need to make more use of these when i'm baffled as to when something is
51 * void *(*__malloc_hook)(size_t size, const void *caller);
53 * void *(*__realloc_hook)(void *ptr, size_t size, const void *caller);
55 * void *(*__memalign_hook)(size_t alignment, size_t size,
56 * const void *caller);
58 * void (*__free_hook)(void *ptr, const void *caller);
60 * void (*__malloc_initialize_hook)(void);
62 * void (*__after_morecore_hook)(void);
65 static void my_init_hook(void);
66 static void my_free_hook(void *p, const void *caller);
68 static void (*old_free_hook)(void *ptr, const void *caller) = NULL;
69 void (*__free_hook)(void *ptr, const void *caller);
71 void (*__malloc_initialize_hook) (void) = my_init_hook;
75 old_free_hook = __free_hook;
76 __free_hook = my_free_hook;
79 //void *magicfree = NULL;
82 my_free_hook(void *p, const void *caller)
84 __free_hook = old_free_hook;
85 // if ((p) && (p == magicfree))
87 // printf("CAUGHT!!!!! %p ...\n", p);
91 __free_hook = my_free_hook;
95 /* local function prototypes */
96 static void _e_main_shutdown(int errcode);
97 static void _e_main_shutdown_push(int (*func)(void));
98 static void _e_main_parse_arguments(int argc, char **argv);
99 static Eina_Bool _e_main_cb_signal_exit(void *data EINA_UNUSED, int ev_type EINA_UNUSED, void *ev EINA_UNUSED);
100 static Eina_Bool _e_main_cb_signal_hup(void *data EINA_UNUSED, int ev_type EINA_UNUSED, void *ev EINA_UNUSED);
101 static int _e_main_dirs_init(void);
102 static int _e_main_dirs_shutdown(void);
103 static int _e_main_path_init(void);
104 static int _e_main_path_shutdown(void);
105 static int _e_main_screens_init(void);
106 static int _e_main_screens_shutdown(void);
107 static void _e_main_desk_save(void);
108 static void _e_main_desk_restore(void);
109 static Eina_Bool _e_main_cb_idle_before(void *data EINA_UNUSED);
110 static Eina_Bool _e_main_cb_idle_after(void *data EINA_UNUSED);
111 static void _e_main_create_wm_ready(void);
112 static void _e_main_hooks_clean(void);
113 static void _e_main_hook_call(E_Main_Hook_Point hookpoint, void *data EINA_UNUSED);
115 /* local variables */
116 static int _e_main_lvl = 0;
117 static int(*_e_main_shutdown_func[MAX_LEVEL]) (void);
119 static Ecore_Idle_Enterer *_idle_before = NULL;
120 static Ecore_Idle_Enterer *_idle_after = NULL;
122 static Eina_List *hooks = NULL;
124 static int _e_main_hooks_delete = 0;
125 static int _e_main_hooks_walking = 0;
127 static Eina_Inlist *_e_main_hooks[] =
129 [E_MAIN_HOOK_MODULE_LOAD_DONE] = NULL,
130 [E_MAIN_HOOK_E_INFO_READY] = NULL,
131 [E_MAIN_HOOK_POST_CLIENT_IDLER_BEFORE] = NULL
134 /* external variables */
135 E_API Eina_Bool starting = EINA_TRUE;
136 E_API Eina_Bool stopping = EINA_FALSE;
139 _xdg_check_str(const char *env, const char *str)
145 for (p = strstr(env, str); p; p++, p = strstr(p, str))
147 if ((!p[len]) || (p[len] == ':')) return EINA_TRUE;
153 _xdg_data_dirs_augment(void)
156 const char *p = e_prefix_get();
157 char newpath[PATH_MAX], buf[PATH_MAX + PATH_MAX + 200];
161 s = e_util_env_get("XDG_DATA_DIRS");
164 Eina_Bool pfxdata, pfx;
166 pfxdata = !_xdg_check_str(s, e_prefix_data_get());
167 snprintf(newpath, sizeof(newpath), "%s/share", p);
168 pfx = !_xdg_check_str(s, newpath);
171 snprintf(buf, sizeof(buf), "%s%s%s%s%s",
172 pfxdata ? e_prefix_data_get() : "",
177 e_util_env_set("XDG_DATA_DIRS", buf);
183 snprintf(buf, sizeof(buf), "%s:%s/share:/usr/local/share:/usr/share", e_prefix_data_get(), p);
184 e_util_env_set("XDG_DATA_DIRS", buf);
187 s = e_util_env_get("XDG_CONFIG_DIRS");
188 snprintf(newpath, sizeof(newpath), "%s/etc/xdg", p);
191 if (!_xdg_check_str(s, newpath))
193 snprintf(buf, sizeof(buf), "%s:%s", newpath, s);
194 e_util_env_set("XDG_CONFIG_DIRS", buf);
200 snprintf(buf, sizeof(buf), "%s:/etc/xdg", newpath);
201 e_util_env_set("XDG_CONFIG_DIRS", buf);
204 s = e_util_env_get("XDG_RUNTIME_DIR");
211 snprintf(buf, sizeof(buf), "/tmp/xdg-XXXXXX");
213 if (!dir) dir = "/tmp";
216 e_util_env_set("XDG_RUNTIME_DIR", dir);
217 snprintf(buf, sizeof(buf), "%s/.e-deleteme", dir);
218 ecore_file_mkdir(buf);
222 /* set menu prefix so we get our e menu */
223 s = e_util_env_get("XDG_MENU_PREFIX");
227 e_util_env_set("XDG_MENU_PREFIX", "e-");
231 _e_main_subsystem_defer(void *data EINA_UNUSED)
233 TRACE_DS_BEGIN(MAIN:SUBSYSTEMS DEFER);
235 /* try to init delayed subsystems */
237 TRACE_DS_BEGIN(MAIN:DEFERRED INTERNAL SUBSYSTEMS INIT);
239 TSB("[DEFERRED] DPMS Init");
242 e_error_message_show(_("Enlightenment cannot set up dpms.\n"));
245 TSE("[DEFERRED] DPMS Init Done");
246 _e_main_shutdown_push(e_dpms_shutdown);
248 TSB("[DEFERRED] E_Dnd Init");
251 e_error_message_show(_("Enlightenment cannot set up its dnd system.\n"));
254 TSE("[DEFERRED] E_Dnd Init Done");
255 _e_main_shutdown_push(e_dnd_shutdown);
257 TSB("[DEFERRED] E_Scale Init");
260 e_error_message_show(_("Enlightenment cannot set up its scale system.\n"));
263 TSE("[DEFERRED] E_Scale Init Done");
264 _e_main_shutdown_push(e_scale_shutdown);
266 TSB("[DEFERRED] E_Test_Helper Init");
267 e_test_helper_init();
268 _e_main_shutdown_push(e_test_helper_shutdown);
269 TSE("[DEFERRED] E_Test_Helper Done");
271 TSB("[DEFERRED] E_INFO_SERVER Init");
272 e_info_server_init();
273 _e_main_shutdown_push(e_info_server_shutdown);
274 TSE("[DEFERRED] E_INFO_SERVER Done");
277 TRACE_DS_BEGIN(MAIN:DEFERRED COMP JOB);
279 /* try to do deferred job of any subsystems*/
280 TSB("[DEFERRED] Compositor's deferred job");
281 e_comp_deferred_job();
282 TSE("[DEFERRED] Compositor's deferred job Done");
284 if (e_config->use_e_policy)
286 TSB("[DEFERRED] E_Policy's deferred job");
287 e_policy_deferred_job();
288 TSE("[DEFERRED] E_Policy's deferred job Done");
291 TSB("[DEFERRED] E_Module's deferred job");
292 e_module_deferred_job();
293 TSE("[DEFERRED] E_Module's deferred job Done");
297 return ECORE_CALLBACK_DONE;
303 _e_main_shutdown(-1);
304 return ECORE_CALLBACK_DONE;
308 _e_main_deferred_job_schedule(void *d EINA_UNUSED, int type EINA_UNUSED, void *ev EINA_UNUSED)
310 PRCTL("[Winsys] all modules loaded");
311 ecore_idler_add(_e_main_subsystem_defer, NULL);
312 return ECORE_CALLBACK_DONE;
315 /* externally accessible functions */
317 main(int argc, char **argv)
320 struct sigaction action;
323 # ifdef PR_SET_PTRACER
324 # ifdef PR_SET_PTRACER_ANY
325 prctl(PR_SET_PTRACER, PR_SET_PTRACER_ANY);
330 #ifdef TIZEN_TEST_GCOV
331 setenv("GCOV_PREFIX", "/tmp", 1);
334 /* for debugging by redirecting stdout & stderr of e to a log file to tail */
335 setvbuf(stdout, NULL, _IONBF, 0);
336 setvbuf(stderr, NULL, _IONBF, 0);
339 t0 = t1 = t2 = ecore_time_unix_get();
340 printf("ESTART(main) %1.5f\n", t0);
342 TRACE_DS_BEGIN(MAIN:BEGIN STARTUP);
343 TSB("Begin Startup");
344 PRCTL("[Winsys] start of main");
346 /* trap deadly bug signals and allow some form of sane recovery */
347 /* or ability to gdb attach and debug at this point - better than your */
348 /* wm/desktop vanishing and not knowing what happened */
350 /* don't install SIGBUS handler */
351 /* Wayland shm sets up a sigbus handler for catching invalid shm region */
352 /* access. If we setup our sigbus handler here, then the wl-shm sigbus */
353 /* handler will not function properly */
354 s = e_util_env_get("NOTIFY_SOCKET");
360 action.sa_sigaction = e_sigseg_act;
361 action.sa_flags = SA_NODEFER | SA_RESETHAND | SA_SIGINFO;
362 sigemptyset(&action.sa_mask);
363 sigaction(SIGSEGV, &action, NULL);
365 action.sa_sigaction = e_sigill_act;
366 action.sa_flags = SA_NODEFER | SA_RESETHAND | SA_SIGINFO;
367 sigemptyset(&action.sa_mask);
368 sigaction(SIGILL, &action, NULL);
370 action.sa_sigaction = e_sigfpe_act;
371 action.sa_flags = SA_NODEFER | SA_RESETHAND | SA_SIGINFO;
372 sigemptyset(&action.sa_mask);
373 sigaction(SIGFPE, &action, NULL);
375 action.sa_sigaction = e_sigabrt_act;
376 action.sa_flags = SA_NODEFER | SA_RESETHAND | SA_SIGINFO;
377 sigemptyset(&action.sa_mask);
378 sigaction(SIGABRT, &action, NULL);
379 TSE("Signal Trap Done");
385 e_error_message_show(_("Enlightenment cannot initialize Eina!\n"));
388 TSE("Eina Init Done");
389 _e_main_shutdown_push(eina_shutdown);
391 #ifdef OBJECT_HASH_CHECK
392 TSB("E_Object Hash Init");
393 e_object_hash_init();
394 TSE("E_Object Hash Init Done");
400 e_error_message_show(_("Enlightenment could not create a logging domain!\n"));
403 TSE("E_Log Init Done");
404 _e_main_shutdown_push(e_log_shutdown);
406 TSB("Determine Prefix");
407 if (!e_prefix_determine(argv[0]))
410 "ERROR: Enlightenment cannot determine it's installed\n"
411 " prefix from the system or argv[0].\n"
412 " This is because it is not on Linux AND has been\n"
413 " executed strangely. This is unusual.\n");
415 TSE("Determine Prefix Done");
417 TSB("Parse Arguments");
418 _e_main_parse_arguments(argc, argv);
419 TSE("Parse Arguments Done");
421 /*** Initialize Core EFL Libraries We Need ***/
426 e_error_message_show(_("Enlightenment cannot initialize Eet!\n"));
429 TSE("Eet Init Done");
430 _e_main_shutdown_push(eet_shutdown);
432 /* Allow ecore to not load system modules.
433 * Without it ecore_init will block until dbus authentication
434 * and registration are complete.
436 ecore_app_no_system_modules();
441 e_error_message_show(_("Enlightenment cannot initialize Ecore!\n"));
444 TSE("Ecore Init Done");
445 _e_main_shutdown_push(ecore_shutdown);
450 e_error_message_show(_("Enlightenment cannot initialize EIO!\n"));
453 TSE("EIO Init Done");
454 _e_main_shutdown_push(eio_shutdown);
456 TSB("Ecore Event Handlers");
457 if (!ecore_event_handler_add(ECORE_EVENT_SIGNAL_EXIT,
458 _e_main_cb_signal_exit, NULL))
460 e_error_message_show(_("Enlightenment cannot set up an exit signal handler.\n"
461 "Perhaps you are out of memory?"));
464 if (!ecore_event_handler_add(ECORE_EVENT_SIGNAL_HUP,
465 _e_main_cb_signal_hup, NULL))
467 e_error_message_show(_("Enlightenment cannot set up a HUP signal handler.\n"
468 "Perhaps you are out of memory?"));
471 TSE("Ecore Event Handlers Done");
473 TSB("Ecore_File Init");
474 if (!ecore_file_init())
476 e_error_message_show(_("Enlightenment cannot initialize Ecore_File!\n"));
479 TSE("Ecore_File Init Done");
480 _e_main_shutdown_push(ecore_file_shutdown);
482 TSB("E_Util_File_Monitor Init");
483 e_util_file_monitor_init();
484 TSE("E_Util_File_Monitor Init Done");
485 _e_main_shutdown_push(e_util_file_monitor_shutdown);
487 _idle_before = ecore_idle_enterer_before_add(_e_main_cb_idle_before, NULL);
489 TSB("XDG_DATA_DIRS Init");
490 _xdg_data_dirs_augment();
491 TSE("XDG_DATA_DIRS Init Done");
493 TSB("Ecore_Evas Init");
494 if (!ecore_evas_init())
496 e_error_message_show(_("Enlightenment cannot initialize Ecore_Evas!\n"));
499 TSE("Ecore_Evas Init Done");
504 e_error_message_show(_("Enlightenment cannot initialize Edje!\n"));
507 TSE("Edje Init Done");
508 _e_main_shutdown_push(edje_shutdown);
510 /*** Initialize E Subsystems We Need ***/
515 e_error_message_show(_("Enlightenment cannot set up user home path\n"));
518 TSE("E User Init Done");
519 _e_main_shutdown_push(e_user_shutdown);
521 TSB("E Directories Init");
522 /* setup directories we will be using for configurations storage etc. */
523 if (!_e_main_dirs_init())
525 e_error_message_show(_("Enlightenment cannot create directories in your home directory.\n"
526 "Perhaps you have no home directory or the disk is full?"));
529 TSE("E Directories Init Done");
530 _e_main_shutdown_push(_e_main_dirs_shutdown);
532 TSB("E_Config Init");
533 if (!e_config_init())
535 e_error_message_show(_("Enlightenment cannot set up its config system.\n"));
538 TSE("E_Config Init Done");
539 _e_main_shutdown_push(e_config_shutdown);
544 e_error_message_show(_("Enlightenment cannot set up its environment.\n"));
547 TSE("E_Env Init Done");
548 _e_main_shutdown_push(e_env_shutdown);
550 ecore_exe_run_priority_set(e_config->priority);
553 if (!_e_main_path_init())
555 e_error_message_show(_("Enlightenment cannot set up paths for finding files.\n"
556 "Perhaps you are out of memory?"));
559 TSE("E Paths Init Done");
560 _e_main_shutdown_push(_e_main_path_shutdown);
562 ecore_animator_frametime_set(1.0 / e_config->framerate);
567 e_error_message_show(_("Enlightenment cannot set up its theme system.\n"));
570 TSE("E_Theme Init Done");
571 _e_main_shutdown_push(e_theme_shutdown);
573 TSB("E_Actions Init");
574 if (!e_actions_init())
576 e_error_message_show(_("Enlightenment cannot set up its actions system.\n"));
579 TSE("E_Actions Init Done");
580 _e_main_shutdown_push(e_actions_shutdown);
582 /* these just add event handlers and can't fail
583 * timestamping them is dumb.
585 e_screensaver_preinit();
590 TRACE_DS_BEGIN(MAIN:WAIT /dev/dri/card0);
591 if (e_config->sleep_for_dri)
593 while(access("/dev/dri/card0", F_OK) != 0)
595 struct timespec req, rem;
597 req.tv_nsec = 50000000L;
598 nanosleep(&req, &rem);
606 e_error_message_show(_("Enlightenment cannot set up its msg system."));
609 TSE("E_Msg Init Done");
610 _e_main_shutdown_push(e_msg_shutdown);
612 e_module_event_init();
614 TSB("E_Pointer Init");
615 if (!e_pointer_init())
617 e_error_message_show(_("Enlightenment cannot set up its pointer system.\n"));
620 TSE("E_Pointer Init Done");
621 _e_main_shutdown_push(e_pointer_shutdown);
623 TRACE_DS_BEGIN(MAIN:SCREEN INIT);
625 if (!_e_main_screens_init())
627 e_error_message_show(_("Enlightenment set up window management for all the screens on your system\n"
628 "failed. Perhaps another window manager is running?\n"));
631 TSE("Screens Init Done");
632 _e_main_shutdown_push(_e_main_screens_shutdown);
635 TSB("E_Devicemgr Init");
636 if (!e_devicemgr_init())
638 e_error_message_show(_("Enlightenment cannot set up its device_manager system.\n"));
641 TSE("E_Devicemgr Init Done");
642 _e_main_shutdown_push(e_devicemgr_shutdown);
644 TSB("E_Keyrouter Init");
645 if (!e_keyrouter_init())
647 e_error_message_show(_("Enlightenment cannot set up its keyrouting system.\n"));
650 TSE("E_Keyrouter Init Done");
651 _e_main_shutdown_push(e_keyrouter_shutdown);
653 if (e_config->eom_enable)
658 e_error_message_show(_("Enlightenment cannot set up eom.\n"));
661 TSE("Eom Init Done");
662 _e_main_shutdown_push(e_eom_shutdown);
665 TSB("E_Screensaver Init");
666 if (!e_screensaver_init())
668 e_error_message_show(_("Enlightenment cannot configure the X screensaver.\n"));
671 TSE("E_Screensaver Init Done");
672 _e_main_shutdown_push(e_screensaver_shutdown);
674 TSB("E_Comp Freeze");
676 TSE("E_Comp Freeze Done");
678 TSB("E_Grabinput Init");
679 if (!e_grabinput_init())
681 e_error_message_show(_("Enlightenment cannot set up its grab input handling system.\n"));
684 TSE("E_Grabinput Init Done");
685 _e_main_shutdown_push(e_grabinput_shutdown);
687 TS("E_Gesture Init");
689 _e_main_shutdown_push(e_gesture_shutdown);
691 ecore_event_handler_add(E_EVENT_MODULE_INIT_END, _e_main_deferred_job_schedule, NULL);
693 TSB("E_Module Init");
694 if (!e_module_init())
696 e_error_message_show(_("Enlightenment cannot set up its module system.\n"));
699 TSE("E_Module Init Done");
700 _e_main_shutdown_push(e_module_shutdown);
703 if (!e_mouse_update())
705 e_error_message_show(_("Enlightenment cannot configure the mouse settings.\n"));
708 TSE("E_Mouse Init Done");
713 e_error_message_show(_("Enlightenment cannot initialize the Icon Cache system.\n"));
716 TSE("E_Icon Init Done");
717 _e_main_shutdown_push(e_icon_shutdown);
719 if (e_config->use_e_policy)
721 TSB("E_Policy Init");
722 if (!e_policy_init())
724 e_error_message_show(_("Enlightenment cannot setup policy system!\n"));
727 TSE("E_Policy Init Done");
728 _e_main_shutdown_push(e_policy_shutdown);
731 TSB("E_Process Init");
732 if (!e_process_init())
734 e_error_message_show(_("Enlightenment cannot setup process managing system!\n"));
737 TSE("E_Process Init Done");
738 _e_main_shutdown_push(e_process_shutdown);
740 TSB("E_Security Init");
741 if (!e_security_init())
743 e_error_message_show(_("Enlightenment cannot setup security system!\n"));
746 TSE("E_Security Init Done");
747 _e_main_shutdown_push(e_security_shutdown);
751 TSE("Load Modules Done");
755 TSE("E_Comp Thaw Done");
757 if (e_config->use_thread_max_cpu)
761 cpus = eina_cpu_count();
764 TSM("Set ecore thread max");
765 ecore_thread_max_set(cpus);
769 _idle_after = ecore_idle_enterer_add(_e_main_cb_idle_after, NULL);
771 starting = EINA_FALSE;
773 TSM("MAIN LOOP AT LAST");
775 if (e_config->create_wm_ready)
776 _e_main_create_wm_ready();
781 TSM("[WM] Send start-up completion");
782 sd_notify(0, "READY=1");
784 TSM("[WM] Skip sending start-up completion. (no systemd)");
786 ecore_main_loop_begin();
788 ELOGF("COMP", "STOPPING enlightenment...", NULL);
789 stopping = EINA_TRUE;
792 e_comp_internal_save();
803 _e_main_shutdown(-1);
807 e_main_ts(const char *str)
810 t1 = ecore_time_unix_get();
811 printf("ESTART: %1.5f [%1.5f] - %s\n", t1 - t0, t1 - t2, str);
818 e_main_ts_begin(const char *str)
820 TRACE_DS_BEGIN(ESTART: %s, str);
821 return e_main_ts(str);
825 e_main_ts_end(const char *str)
828 return e_main_ts(str);
831 /* local functions */
833 _e_main_shutdown(int errcode)
839 printf("E: Begin Shutdown Procedure!\n");
841 E_FREE_LIST(hooks, e_main_hook_del);
843 if (_idle_before) ecore_idle_enterer_del(_idle_before);
845 if (_idle_after) ecore_idle_enterer_del(_idle_after);
848 dir = e_util_env_get("XDG_RUNTIME_DIR");
851 char buf_env[PATH_MAX - 12];
852 snprintf(buf_env, sizeof(buf_env), "%s", dir);
853 snprintf(buf, sizeof(buf), "%s/.e-deleteme", buf_env);
854 if (ecore_file_exists(buf)) ecore_file_recursive_rm(buf_env);
857 for (i = (_e_main_lvl - 1); i >= 0; i--)
858 (*_e_main_shutdown_func[i])();
859 #ifdef OBJECT_HASH_CHECK
860 e_object_hash_shutdown();
862 if (errcode < 0) exit(errcode);
866 _e_main_shutdown_push(int (*func)(void))
869 if (_e_main_lvl > MAX_LEVEL)
872 e_error_message_show("WARNING: too many init levels. MAX = %i\n",
876 _e_main_shutdown_func[_e_main_lvl - 1] = func;
880 _e_main_parse_arguments(int argc, char **argv)
884 /* handle some command-line parameters */
885 for (i = 1; i < argc; i++)
887 if ((!strcmp(argv[i], "-profile")) && (i < (argc - 1)))
890 if (!getenv("E_CONF_PROFILE"))
891 e_util_env_set("E_CONF_PROFILE", argv[i]);
893 else if ((!strcmp(argv[i], "-version")) ||
894 (!strcmp(argv[i], "--version")))
896 printf(_("Version: %s\n"), PACKAGE_VERSION);
897 _e_main_shutdown(-1);
899 else if ((!strcmp(argv[i], "-h")) ||
900 (!strcmp(argv[i], "-help")) ||
901 (!strcmp(argv[i], "--help")))
906 "\t-profile CONF_PROFILE\n"
907 "\t\tUse the configuration profile CONF_PROFILE instead of the user selected default or just \"default\".\n"
911 _e_main_shutdown(-1);
917 _e_main_cb_signal_exit(void *data EINA_UNUSED, int ev_type EINA_UNUSED, void *ev EINA_UNUSED)
919 /* called on ctrl-c, kill (pid) (also SIGINT, SIGTERM and SIGQIT) */
920 ecore_main_loop_quit();
921 return ECORE_CALLBACK_RENEW;
925 _e_main_cb_signal_hup(void *data EINA_UNUSED, int ev_type EINA_UNUSED, void *ev EINA_UNUSED)
927 ecore_main_loop_quit();
928 return ECORE_CALLBACK_RENEW;
932 _e_main_dirs_init(void)
934 if(getenv("E_CONF_RO"))
948 base = e_user_dir_get();
949 if (ecore_file_mksubdirs(base, dirs) != sizeof(dirs) / sizeof(dirs[0]) - 1)
951 e_error_message_show("Could not create one of the required "
952 "subdirectories of '%s'\n", base);
960 _e_main_dirs_shutdown(void)
966 _e_main_path_init(void)
970 /* setup data paths */
971 path_data = e_path_new();
974 e_error_message_show("Cannot allocate path for path_data\n");
977 e_prefix_data_concat_static(buf, "data");
978 e_path_default_path_append(path_data, buf);
980 /* setup image paths */
981 path_images = e_path_new();
984 e_error_message_show("Cannot allocate path for path_images\n");
987 e_user_dir_concat_static(buf, "/images");
988 e_path_default_path_append(path_images, buf);
989 e_prefix_data_concat_static(buf, "data/images");
990 e_path_default_path_append(path_images, buf);
992 /* setup font paths */
993 path_fonts = e_path_new();
996 e_error_message_show("Cannot allocate path for path_fonts\n");
999 e_user_dir_concat_static(buf, "/fonts");
1000 e_path_default_path_append(path_fonts, buf);
1001 e_prefix_data_concat_static(buf, "data/fonts");
1002 e_path_default_path_append(path_fonts, buf);
1004 /* setup icon paths */
1005 path_icons = e_path_new();
1008 e_error_message_show("Cannot allocate path for path_icons\n");
1011 e_user_dir_concat_static(buf, "/icons");
1012 e_path_default_path_append(path_icons, buf);
1013 e_prefix_data_concat_static(buf, "data/icons");
1014 e_path_default_path_append(path_icons, buf);
1016 /* setup module paths */
1017 path_modules = e_path_new();
1020 e_error_message_show("Cannot allocate path for path_modules\n");
1023 e_user_dir_concat_static(buf, "/modules");
1024 e_path_default_path_append(path_modules, buf);
1025 snprintf(buf, sizeof(buf), "%s/enlightenment/modules", e_prefix_lib_get());
1026 e_path_default_path_append(path_modules, buf);
1027 /* FIXME: eventually this has to go - moduels should have installers that
1028 * add appropriate install paths (if not installed to user homedir) to
1029 * e's module search dirs
1031 snprintf(buf, sizeof(buf), "%s/enlightenment/modules_extra", e_prefix_lib_get());
1032 e_path_default_path_append(path_modules, buf);
1034 /* setup background paths */
1035 path_backgrounds = e_path_new();
1036 if (!path_backgrounds)
1038 e_error_message_show("Cannot allocate path for path_backgrounds\n");
1041 e_user_dir_concat_static(buf, "/backgrounds");
1042 e_path_default_path_append(path_backgrounds, buf);
1043 e_prefix_data_concat_static(buf, "data/backgrounds");
1044 e_path_default_path_append(path_backgrounds, buf);
1046 path_messages = e_path_new();
1049 e_error_message_show("Cannot allocate path for path_messages\n");
1052 e_user_dir_concat_static(buf, "/locale");
1053 e_path_default_path_append(path_messages, buf);
1054 e_path_default_path_append(path_messages, e_prefix_locale_get());
1060 _e_main_path_shutdown(void)
1064 e_object_del(E_OBJECT(path_data));
1069 e_object_del(E_OBJECT(path_images));
1074 e_object_del(E_OBJECT(path_fonts));
1079 e_object_del(E_OBJECT(path_icons));
1084 e_object_del(E_OBJECT(path_modules));
1085 path_modules = NULL;
1087 if (path_backgrounds)
1089 e_object_del(E_OBJECT(path_backgrounds));
1090 path_backgrounds = NULL;
1094 e_object_del(E_OBJECT(path_messages));
1095 path_messages = NULL;
1101 _e_main_screens_init(void)
1103 TSB("\tscreens: client");
1104 if (!e_client_init()) return 0;
1105 TSE("\tscreens: client Done");
1107 TSB("Compositor Init");
1108 PRCTL("[Winsys] start of compositor init");
1111 e_error_message_show(_("Enlightenment cannot create a compositor.\n"));
1112 _e_main_shutdown(-1);
1114 TSE("Compositor Init Done");
1116 PRCTL("[Winsys] end of compositor init");
1117 _e_main_desk_restore();
1123 _e_main_screens_shutdown(void)
1126 e_client_shutdown();
1128 e_magnifier_shutdown();
1135 _e_main_desk_save(void)
1138 char env[1024], name[1024];
1141 EINA_LIST_FOREACH(e_comp->zones, l, zone)
1143 snprintf(name, sizeof(name), "DESK_%d_%d", 0, zone->num);
1144 snprintf(env, sizeof(env), "%d,%d", zone->desk_x_current, zone->desk_y_current);
1145 e_util_env_set(name, env);
1150 _e_main_desk_restore(void)
1155 E_CLIENT_REVERSE_FOREACH(ec)
1157 zone = e_comp_zone_find_by_ec(ec);
1158 if ((!e_client_util_ignored_get(ec)) && e_desk_has_ec(e_desk_current_get(zone), ec))
1160 ec->want_focus = ec->take_focus = 1;
1167 _e_main_cb_idle_before(void *data EINA_UNUSED)
1169 e_comp_idler_before();
1170 _e_main_hook_call(E_MAIN_HOOK_POST_CLIENT_IDLER_BEFORE, NULL);
1173 return ECORE_CALLBACK_RENEW;
1177 _e_main_cb_idle_after(void *data EINA_UNUSED)
1179 static int first_idle = 1;
1190 return ECORE_CALLBACK_RENEW;
1194 _e_main_create_wm_ready(void)
1196 FILE *_wmready_checker = NULL;
1197 const char *path_wm_ready = "/run/.wm_ready";
1199 if (!e_util_file_realpath_check(path_wm_ready, EINA_TRUE))
1201 WRN("%s is maybe link, so delete it\n", path_wm_ready);
1204 _wmready_checker = fopen(path_wm_ready, "wb");
1205 if (_wmready_checker)
1207 TSM("[WM] WINDOW MANAGER is READY!!!");
1208 PRCTL("[Winsys] WINDOW MANAGER is READY!!!");
1209 fclose(_wmready_checker);
1211 /*TODO: Next lines should be removed. */
1212 FILE *_tmp_wm_ready_checker;
1214 _tmp_wm_ready_checker = fopen(path_wm_ready, "wb");
1216 if (_tmp_wm_ready_checker)
1218 TSM("[WM] temporary wm_ready path is created.");
1219 PRCTL("[Winsys] temporary wm_ready path is created.");
1220 fclose(_tmp_wm_ready_checker);
1224 TSM("[WM] temporary wm_ready path create failed.");
1225 PRCTL("[Winsys] temporary wm_ready path create failed.");
1230 TSM("[WM] WINDOW MANAGER is READY. BUT, failed to create .wm_ready file.");
1231 PRCTL("[Winsys] WINDOW MANAGER is READY. BUT, failed to create .wm_ready file.");
1236 _e_main_hooks_clean(void)
1242 for (x = 0; x < E_MAIN_HOOK_LAST; x++)
1243 EINA_INLIST_FOREACH_SAFE(_e_main_hooks[x], l, mh)
1245 if (!mh->delete_me) continue;
1246 _e_main_hooks[x] = eina_inlist_remove(_e_main_hooks[x],
1247 EINA_INLIST_GET(mh));
1253 _e_main_hook_call(E_Main_Hook_Point hookpoint, void *data EINA_UNUSED)
1257 _e_main_hooks_walking++;
1258 EINA_INLIST_FOREACH(_e_main_hooks[hookpoint], mh)
1260 if (mh->delete_me) continue;
1263 _e_main_hooks_walking--;
1264 if ((_e_main_hooks_walking == 0) && (_e_main_hooks_delete > 0))
1265 _e_main_hooks_clean();
1269 e_main_hook_add(E_Main_Hook_Point hookpoint, E_Main_Hook_Cb func, const void *data)
1273 EINA_SAFETY_ON_TRUE_RETURN_VAL(hookpoint >= E_MAIN_HOOK_LAST, NULL);
1274 mh = E_NEW(E_Main_Hook, 1);
1275 EINA_SAFETY_ON_NULL_RETURN_VAL(mh, NULL);
1276 mh->hookpoint = hookpoint;
1278 mh->data = (void*)data;
1279 _e_main_hooks[hookpoint] = eina_inlist_append(_e_main_hooks[hookpoint],
1280 EINA_INLIST_GET(mh));
1285 e_main_hook_del(E_Main_Hook *mh)
1288 if (_e_main_hooks_walking == 0)
1290 _e_main_hooks[mh->hookpoint] = eina_inlist_remove(_e_main_hooks[mh->hookpoint],
1291 EINA_INLIST_GET(mh));
1295 _e_main_hooks_delete++;
1299 e_main_hook_call(E_Main_Hook_Point hookpoint)
1301 if ((hookpoint < 0) || (hookpoint >= E_MAIN_HOOK_LAST)) return;
1303 _e_main_hook_call(hookpoint, NULL);