You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1826 lines
54 KiB

#include "e.h"
#ifdef __linux__
# include <sys/prctl.h>
#endif
#include "valgrind.h"
#define MAX_LEVEL 80
#define TS_DO
#ifdef TS_DO
# define TS(x) \
{ \
t1 = ecore_time_unix_get(); \
printf("ESTART: %1.5f [%1.5f] - %s\n", t1 - t0, t1 - t2, x); \
t2 = t1; \
}
static double t0, t1, t2;
#else
# define TS(x)
#endif
/*
* i need to make more use of these when i'm baffled as to when something is
* up. other hooks:
*
* void *(*__malloc_hook)(size_t size, const void *caller);
*
* void *(*__realloc_hook)(void *ptr, size_t size, const void *caller);
*
* void *(*__memalign_hook)(size_t alignment, size_t size,
* const void *caller);
*
* void (*__free_hook)(void *ptr, const void *caller);
*
* void (*__malloc_initialize_hook)(void);
*
* void (*__after_morecore_hook)(void);
*
static void my_init_hook(void);
static void my_free_hook(void *p, const void *caller);
static void (*old_free_hook)(void *ptr, const void *caller) = NULL;
void (*__free_hook)(void *ptr, const void *caller);
void (*__malloc_initialize_hook) (void) = my_init_hook;
static void
my_init_hook(void)
{
old_free_hook = __free_hook;
__free_hook = my_free_hook;
}
//void *magicfree = NULL;
static void
my_free_hook(void *p, const void *caller)
{
__free_hook = old_free_hook;
// if ((p) && (p == magicfree))
// {
// printf("CAUGHT!!!!! %p ...\n", p);
// abort();
// }
free(p);
__free_hook = my_free_hook;
}
*/
/* local function prototypes */
static void _e_main_shutdown(int errcode);
static void _e_main_shutdown_push(int (*func)(void));
static void _e_main_parse_arguments(int argc, char **argv);
static Eina_Bool _e_main_cb_signal_exit(void *data EINA_UNUSED, int ev_type EINA_UNUSED, void *ev EINA_UNUSED);
static Eina_Bool _e_main_cb_signal_hup(void *data EINA_UNUSED, int ev_type EINA_UNUSED, void *ev EINA_UNUSED);
static Eina_Bool _e_main_cb_signal_user(void *data EINA_UNUSED, int ev_type EINA_UNUSED, void *ev);
static int _e_main_dirs_init(void);
static int _e_main_dirs_shutdown(void);
static int _e_main_path_init(void);
static int _e_main_path_shutdown(void);
static int _e_main_screens_init(void);
static int _e_main_screens_shutdown(void);
static void _e_main_desk_save(void);
compositor rewrite / charlie-foxtrot situation huge fustercluck commit because there wasn't really a way to separate out the changes. better to just rip it all out at once. * compositor and window management completely rewritten. this was the goal for E19, but it pretty much required everything existing to be scrapped since it wasn't optimized, streamlined, or sensible. now instead of having the compositor strapped to the window manager like an outboard motor, it's housed more like an automobile engine. ** various comp structs have been merged into other places (eg. E_Comp_Zone is now just part of E_Zone where applicable), leading to a large deduplication of attributes ** awful E_Comp_Win is totally dead, having been replaced with e_comp_object smart objects which work just like normal canvas objects ** protocol-specific window management and compositor functionality is now kept exclusively in backend files ** e_pixmap api provides generic client finding and rendering api ** screen/xinerama screens are now provided directly by compositor on startup and re-set on change ** e_comp_render_update finally replaced with eina_tiler ** wayland compositor no longer creates X windows ** compositor e_layout removed entirely * e_container is gone. this was made unnecessary in E18, but I kept it to avoid having too much code churn in one release. its sole purpose was to catch some events and handle window stacking, both of which are now just done by the compositor infra * e_manager is just for screensaver and keybind stuff now, possibly remove later? * e_border is gone along with a lot of its api. e_client has replaced it, and e_client has been rewritten completely; some parts may be similar, but the design now relies upon having a functional compositor ** window configuration/focus functions are all removed. all windows are now managed solely with evas_object_X functions on the "frame" member of a client, just as any other canvas object can be managed. *** do NOT set interceptors on a client's comp_object. seriously. * startup order rewritten: compositor now starts much earlier, other things just use attrs and members of the compositor * ecore_x_pointer_xy_get usage replaced with ecore_evas_pointer_xy_get * e_popup is totally gone, existing usage replaced by e_comp_object_util_add where applicable, otherwise just placed normally on the canvas * deskmirror is (more) broken for now * illume is totally fucked * Ecore_X_Window replaced with Ecore_Window in most cases * edge binding XWindows replaced with regular canvas objects * some E_Win functionality has changed such that delete callbacks are now correctly called in ALL cases. various dialogs have been updated to not crash as a result comp files and descriptions: e_comp.c - overall compositor functions, rendering/update loop, shape cutting e_comp_x.c - X window management and compositor functionality e_comp_wl.c - Wayland surface management and compositor functionality e_comp_canvas.c - general compositor canvas functions and utilities e_comp_object.c - E_Client->frame member for managing clients as Evas_Objects, utility functions for adding objects to the compositor rendering systems additional authors: ivan.briano@intel.com feature: new compositor removal: e_border, e_container, e_popup
9 years ago
static void _e_main_desk_restore(void);
static void _e_main_efreet_paths_init(void);
static void _e_main_modules_load(Eina_Bool safe_mode);
static Eina_Bool _e_main_cb_idle_before(void *data EINA_UNUSED);
static Eina_Bool _e_main_cb_idle_after(void *data EINA_UNUSED);
static Eina_Bool _e_main_cb_startup_fake_end(void *data EINA_UNUSED);
/* local variables */
static Eina_Bool really_know = EINA_FALSE;
static Eina_Bool locked = EINA_FALSE;
static Eina_Bool inloop = EINA_FALSE;
static jmp_buf x_fatal_buff;
static int _e_main_lvl = 0;
static int(*_e_main_shutdown_func[MAX_LEVEL]) (void);
static Ecore_Idle_Enterer *_idle_before = NULL;
static Ecore_Idle_Enterer *_idle_after = NULL;
static Ecore_Event_Handler *mod_init_end = NULL;
/* external variables */
E_API Eina_Bool e_precache_end = EINA_FALSE;
E_API Eina_Bool x_fatal = EINA_FALSE;
E_API Eina_Bool good = EINA_FALSE;
E_API Eina_Bool evil = EINA_FALSE;
E_API Eina_Bool starting = EINA_TRUE;
E_API Eina_Bool stopping = EINA_FALSE;
E_API Eina_Bool restart = EINA_FALSE;
E_API Eina_Bool e_nopause = EINA_FALSE;
E_API Eina_Bool after_restart = EINA_FALSE;
E_API Eina_Bool e_main_loop_running = EINA_FALSE;
EINTERN const char *e_first_frame = NULL;
EINTERN double e_first_frame_start_time = -1;
static Eina_Bool
_xdg_check_str(const char *env, const char *str)
{
const char *p;
size_t len;
len = strlen(str);
for (p = strstr(env, str); p; p++, p = strstr(p, str))
{
if ((!p[len]) || (p[len] == ':')) return EINA_TRUE;
}
return EINA_FALSE;
}
static void
_xdg_data_dirs_augment(void)
{
const char *s;
const char *p = e_prefix_get();
char newpath[PATH_MAX], buf[PATH_MAX + PATH_MAX + 200];
if (!p) return;
s = getenv("XDG_DATA_DIRS");
if (s)
{
Eina_Bool pfxdata, pfx;
pfxdata = !_xdg_check_str(s, e_prefix_data_get());
snprintf(newpath, sizeof(newpath), "%s/share", p);
pfx = !_xdg_check_str(s, newpath);
if (pfxdata || pfx)
{
snprintf(buf, sizeof(buf), "%s%s%s%s%s",
pfxdata ? e_prefix_data_get() : "",
pfxdata ? ":" : "",
pfx ? newpath : "",
pfx ? ":" : "",
s);
e_util_env_set("XDG_DATA_DIRS", buf);
}
}
else
{
snprintf(buf, sizeof(buf), "%s:%s/share:/usr/local/share:/usr/share", e_prefix_data_get(), p);
e_util_env_set("XDG_DATA_DIRS", buf);
}
s = getenv("XDG_CONFIG_DIRS");
snprintf(newpath, sizeof(newpath), "%s/etc/xdg", p);
if (s)
{
if (!_xdg_check_str(s, newpath))
{
snprintf(buf, sizeof(buf), "%s:%s", newpath, s);
e_util_env_set("XDG_CONFIG_DIRS", buf);
}
}
else
{
snprintf(buf, sizeof(buf), "%s:/etc/xdg", newpath);
e_util_env_set("XDG_CONFIG_DIRS", buf);
}
// N.B. XDG_RUNTIME_DIR is taken care of in e_start
/* set menu prefix so we get our e menu */
if (!getenv("XDG_MENU_PREFIX"))
{
e_util_env_set("XDG_MENU_PREFIX", "e-");
}
}
static Eina_Bool
_precache_file(const Eina_Hash *hash EINA_UNUSED, const void *key, void *data EINA_UNUSED, void *fdata)
{
Eina_List **precache_files = fdata;
*precache_files = eina_list_append(*precache_files, strdup(key));
return EINA_TRUE;
}
static void *
_precache_thread(void *data, Eina_Thread thr EINA_UNUSED)
{
Eina_List *precache_files = data;
char *path;
double t = ecore_time_get();
unsigned int sum = 0;
unsigned int reads = 0;
printf("PRECACHE: BEGIN\n");
EINA_LIST_FREE(precache_files, path)
{
double tt = ecore_time_get();
FILE *f = fopen(path, "r");
unsigned char buf[4096];
if (f)
{
size_t sz;
while ((sz = fread(buf, 1, sizeof(buf), f)) > 0)
{
reads ++;
sum = ((sum << 1) ^ buf[0]) + reads;
}
fclose(f);
}
printf("PRECACHE: [%1.5f] [%s] DONE\n", ecore_time_get() - tt, path);
free(path);
}
printf("PRECACHE: TOTAL [%1.5f]\n", ecore_time_get() - t);
printf("PRECACHE: SUM=%08x, READS=%i\n", sum, reads);
return NULL;
}
/* externally accessible functions */
int
main(int argc, char **argv)
{
Eina_Bool nostartup = EINA_FALSE;
Eina_Bool safe_mode = EINA_FALSE;
Eina_Bool waslocked = EINA_FALSE;
Eina_Stringshare *strshare;
char *s = NULL;
struct sigaction action;
#ifdef __linux__
# ifdef PR_SET_PTRACER
# ifdef PR_SET_PTRACER_ANY
prctl(PR_SET_PTRACER, PR_SET_PTRACER_ANY);
# endif
# endif
#endif
#ifdef TS_DO
t0 = t1 = t2 = ecore_time_unix_get();
#endif
TS("Begin Startup");
/* trap deadly bug signals and allow some form of sane recovery */
/* or ability to gdb attach and debug at this point - better than your */
/* wm/desktop vanishing and not knowing what happened */
if (!getenv("NOTIFY_SOCKET"))
{
TS("Signal Trap");
action.sa_sigaction = e_sigseg_act;
action.sa_flags = SA_NODEFER | SA_RESETHAND | SA_SIGINFO;
sigemptyset(&action.sa_mask);
sigaction(SIGSEGV, &action, NULL);
action.sa_sigaction = e_sigill_act;
action.sa_flags = SA_NODEFER | SA_RESETHAND | SA_SIGINFO;
sigemptyset(&action.sa_mask);
sigaction(SIGILL, &action, NULL);
action.sa_sigaction = e_sigfpe_act;
action.sa_flags = SA_NODEFER | SA_RESETHAND | SA_SIGINFO;
sigemptyset(&action.sa_mask);
sigaction(SIGFPE, &action, NULL);
#ifndef HAVE_WAYLAND_ONLY
action.sa_sigaction = e_sigbus_act;
action.sa_flags = SA_NODEFER | SA_RESETHAND | SA_SIGINFO;
sigemptyset(&action.sa_mask);
sigaction(SIGBUS, &action, NULL);
#endif
action.sa_sigaction = e_sigabrt_act;
action.sa_flags = SA_NODEFER | SA_RESETHAND | SA_SIGINFO;
sigemptyset(&action.sa_mask);
sigaction(SIGABRT, &action, NULL);
TS("Signal Trap Done");
}
TS("Eina Init");
if (!eina_init())
{
e_error_message_show(_("Enlightenment cannot initialize Eina!\n"));
_e_main_shutdown(101);
}
eina_file_statgen_enable();
_e_main_shutdown_push(eina_shutdown);
if (!e_log_init())
{
e_error_message_show(_("Enlightenment could not create a logging domain!\n"));
_e_main_shutdown(101);
}
#ifdef TS_DO
#undef TS
# define TS(x) \
{ \
t1 = ecore_time_unix_get(); \
printf("ESTART: %1.5f [%1.5f] - %s\n", t1 - t0, t1 - t2, x); \
t2 = t1; \
}
#endif
TS("Eina Init Done");
_e_main_shutdown_push(e_log_shutdown);
TS("Determine Prefix");
if (!e_prefix_determine(argv[0]))
{
fprintf(stderr,
"ERROR: Enlightenment cannot determine it's installed\n"
" prefix from the system or argv[0].\n"
" This is because it is not on Linux AND has been\n"
" executed strangely. This is unusual.\n");
}
TS("Determine Prefix Done");
/* Eio's eio_init internally calls efreet_init. Set XDG_MENU_PREFIX here */
/* else efreet's efreet_menu_prefix symbol is set erroneously during eio_init. */
_xdg_data_dirs_augment();
/* for debugging by redirecting stdout of e to a log file to tail */
setvbuf(stdout, NULL, _IONBF, 0);
TS("Environment Variables");
if (getenv("E_RESTART")) after_restart = EINA_TRUE;
if (getenv("DESKTOP_STARTUP_ID"))
e_util_env_set("DESKTOP_STARTUP_ID", NULL);
e_util_env_set("E_RESTART_OK", NULL);
e_util_env_set("PANTS", "ON");
e_util_env_set("DESKTOP", "Enlightenment");
e_util_env_set("XDG_CURRENT_DESKTOP", "Enlightenment");
if (getenv("E_ALERT_FONT_DIR"))
e_util_env_set("E_ALERT_FONT_DIR", NULL);
if (getenv("E_ALERT_SYSTEM_BIN"))
e_util_env_set("E_ALERT_SYSTEM_BIN", NULL);
strshare = eina_stringshare_printf("%s/enlightenment_askpass",
e_prefix_bin_get());
if (strshare)
{
e_util_env_set("SUDO_ASKPASS", strshare);
e_util_env_set("SSH_ASKPASS", strshare);
eina_stringshare_del(strshare);
}
TS("Environment Variables Done");
TS("Parse Arguments");
_e_main_parse_arguments(argc, argv);
TS("Parse Arguments Done");
/*** Initialize Core EFL Libraries We Need ***/
TS("Eet Init");
if (!eet_init())
{
e_error_message_show(_("Enlightenment cannot initialize Eet!\n"));
_e_main_shutdown(101);
}
TS("Eet Init Done");
_e_main_shutdown_push(eet_shutdown);
TS("Ecore Init");
if (!ecore_init())
{
e_error_message_show(_("Enlightenment cannot initialize Ecore!\n"));
_e_main_shutdown(101);
}
TS("Ecore Init Done");
_e_main_shutdown_push(ecore_shutdown);
TS("E Comp Canvas Intercept Init");
e_comp_canvas_intercept();
TS("E Comp Canvas Intercept Init Done");
e_first_frame = getenv("E_FIRST_FRAME");
if (e_first_frame && e_first_frame[0])
e_first_frame_start_time = ecore_time_get();
else
e_first_frame = NULL;
TS("EFX Init");
if (!e_efx_init())
{
e_error_message_show(_("Enlightenment cannot initialize EFX!\n"));
_e_main_shutdown(101);
}
TS("EFX Init Done");
_e_main_shutdown_push((void*)e_efx_shutdown);
TS("EIO Init");
if (!eio_init())
{
e_error_message_show(_("Enlightenment cannot initialize EIO!\n"));
_e_main_shutdown(101);
}
TS("EIO Init Done");
_e_main_shutdown_push(eio_shutdown);
ecore_app_args_set(argc, (const char **)argv);
TS("Ecore Event Handlers");
if (!ecore_event_handler_add(ECORE_EVENT_SIGNAL_EXIT,
_e_main_cb_signal_exit, NULL))
{
e_error_message_show(_("Enlightenment cannot set up an exit signal handler.\n"
"Perhaps you are out of memory?"));
_e_main_shutdown(101);
}
if (!ecore_event_handler_add(ECORE_EVENT_SIGNAL_HUP,
_e_main_cb_signal_hup, NULL))
{
e_error_message_show(_("Enlightenment cannot set up a HUP signal handler.\n"
"Perhaps you are out of memory?"));
_e_main_shutdown(101);
}
if (!ecore_event_handler_add(ECORE_EVENT_SIGNAL_USER,
_e_main_cb_signal_user, NULL))
{
e_error_message_show(_("Enlightenment cannot set up a USER signal handler.\n"
"Perhaps you are out of memory?"));
_e_main_shutdown(101);
}
TS("Ecore Event Handlers Done");
TS("Ecore_File Init");
if (!ecore_file_init())
{
e_error_message_show(_("Enlightenment cannot initialize Ecore_File!\n"));
_e_main_shutdown(101);
}
TS("Ecore_File Init Done");
_e_main_shutdown_push(ecore_file_shutdown);
TS("Ecore_Con Init");
if (!ecore_con_init())
{
e_error_message_show(_("Enlightenment cannot initialize Ecore_Con!\n"));
_e_main_shutdown(101);
}
TS("Ecore_Con Init Done");
_e_main_shutdown_push(ecore_con_shutdown);
TS("Ecore_Ipc Init");
if (!ecore_ipc_init())
{
e_error_message_show(_("Enlightenment cannot initialize Ecore_Ipc!\n"));
_e_main_shutdown(101);
}
TS("Ecore_Ipc Init Done");
_e_main_shutdown_push(ecore_ipc_shutdown);
_idle_before = ecore_idle_enterer_before_add(_e_main_cb_idle_before, NULL);
TS("Ecore_Evas Init");
if (!ecore_evas_init())
{
e_error_message_show(_("Enlightenment cannot initialize Ecore_Evas!\n"));
_e_main_shutdown(101);
}
TS("Ecore_Evas Init Done");
// _e_main_shutdown_push(ecore_evas_shutdown);
TS("Elementary Init");
if (!elm_init(argc, argv))
{
e_error_message_show(_("Enlightenment cannot initialize Elementary!\n"));
_e_main_shutdown(101);
}
TS("Elementary Init Done");
//_e_main_shutdown_push(elm_shutdown);
TS("Emotion Init");
if (!emotion_init())
{
e_error_message_show(_("Enlightenment cannot initialize Emotion!\n"));
_e_main_shutdown(101);
}
TS("Emotion Init Done");
/* triggers event flush: do not call */
//_e_main_shutdown_push((void *)emotion_shutdown);
/* e doesn't sync to compositor - it should be one */
ecore_evas_app_comp_sync_set(0);
TS("Ecore_Evas Engine Check");
#ifdef HAVE_WAYLAND_ONLY
if (!ecore_evas_engine_type_supported_get(ECORE_EVAS_ENGINE_WAYLAND_SHM))
{
e_error_message_show(_("Enlightenment found ecore_evas doesn't support the Wayland SHM\n"
"rendering in Evas. Please check your installation of Evas and\n"
"Ecore and check they support the Wayland SHM rendering engine."));
_e_main_shutdown(101);
}
#else
if (!ecore_evas_engine_type_supported_get(ECORE_EVAS_ENGINE_SOFTWARE_XCB))
{
if (!ecore_evas_engine_type_supported_get(ECORE_EVAS_ENGINE_SOFTWARE_XLIB))
{
e_error_message_show(_("Enlightenment found ecore_evas doesn't support the Software X11\n"
"rendering in Evas. Please check your installation of Evas and\n"
"Ecore and check they support the Software X11 rendering engine."));
_e_main_shutdown(101);
}
}
#endif
if (!ecore_evas_engine_type_supported_get(ECORE_EVAS_ENGINE_SOFTWARE_BUFFER))
{
e_error_message_show(_("Enlightenment found ecore_evas doesn't support the Software Buffer\n"
"rendering in Evas. Please check your installation of Evas and\n"
"Ecore and check they support the Software Buffer rendering engine."));
_e_main_shutdown(101);
}
TS("Ecore_Evas Engine Check Done");
edje_freeze();
/*** Initialize E Subsystems We Need ***/
TS("E Intl Init");
if (!e_intl_init())
{
e_error_message_show(_("Enlightenment cannot initialize E_Intl!\n"));
_e_main_shutdown(101);
}
TS("E Intl Init Done");
_e_main_shutdown_push(e_intl_shutdown);
#ifndef HAVE_WAYLAND_ONLY
/* init white box of death alert */
TS("E_Alert Init");
if (!e_alert_init())
{
e_error_message_show(_("Enlightenment cannot initialize its emergency alert system.\n"
"Have you set your DISPLAY variable?"));
_e_main_shutdown(101);
}
TS("E_Alert Init Done");
_e_main_shutdown_push(e_alert_shutdown);
#endif
TS("E Directories Init");
/* setup directories we will be using for configurations storage etc. */
if (!_e_main_dirs_init())
{
e_error_message_show(_("Enlightenment cannot create directories in your home directory.\n"
"Perhaps you have no home directory or the disk is full?"));
_e_main_shutdown(101);
}
TS("E Directories Init Done");
_e_main_shutdown_push(_e_main_dirs_shutdown);