1.[E_BORDER] Change code to hide the client window in _e_border_cb_window_hide().
[platform/core/uifw/e17.git] / src / bin / e_init.c
1 #include "e.h"
2
3 EAPI int E_EVENT_INIT_DONE = 0;
4
5 /* local function prototypes */
6 static Eina_Bool _e_init_cb_exe_event_del(void *data __UNUSED__, int type __UNUSED__, void *event);
7
8 /* local variables */
9 static const char *title = NULL;
10 static const char *version = NULL;
11 static Ecore_Exe *init_exe = NULL;
12 static Ecore_Event_Handler *exe_del_handler = NULL;
13 static Ecore_Ipc_Client *client = NULL;
14 static int done = 0;
15 static int undone = 0;
16 static Eina_List *stats = NULL;
17
18 /* public functions */
19 EINTERN int
20 e_init_init(void)
21 {
22    E_EVENT_INIT_DONE = ecore_event_type_new();
23    exe_del_handler =
24      ecore_event_handler_add(ECORE_EXE_EVENT_DEL,
25                              _e_init_cb_exe_event_del, NULL);
26    client = NULL;
27    done = 0;
28    return 1;
29 }
30
31 EINTERN int
32 e_init_shutdown(void)
33 {
34    /* if not killed, kill init */
35    e_init_hide();
36    if (title) eina_stringshare_del(title);
37    if (version) eina_stringshare_del(version);
38    title = NULL;
39    version = NULL;
40    if (exe_del_handler) ecore_event_handler_del(exe_del_handler);
41    exe_del_handler = NULL;
42    return 1;
43 }
44
45 EAPI void
46 e_init_show(void)
47 {
48    char buf[8192], *theme, *tit, *ver;
49    const char *s = NULL;
50
51    /* exec init */
52
53    if (!e_config->init_default_theme)
54      s = e_path_find(path_themes, "default.edj");
55    else if (e_config->init_default_theme[0] == '/')
56      s = eina_stringshare_add(e_config->init_default_theme);
57    else
58      s = e_path_find(path_themes, e_config->init_default_theme);
59
60    if (s) theme = strdup(e_util_filename_escape(s));
61    else theme = strdup("XdX");
62    if (s) eina_stringshare_del(s);
63
64    if (title) tit = strdup(e_util_filename_escape(title));
65    else tit = strdup("XtX");
66
67    if (version) ver = strdup(e_util_filename_escape(version));
68    else ver = strdup("XvX");
69
70    snprintf(buf, sizeof(buf),
71             "%s/enlightenment/utils/enlightenment_init \'%s\' \'%i\' \'%s\' \'%s\'",
72             e_prefix_lib_get(), theme,
73             e_config->font_hinting, tit, ver);
74    printf("RUN INIT: %s\n", buf);
75    free(theme);
76    free(tit);
77    free(ver);
78    /* FIXME: add font path to cmd-line */
79    init_exe = ecore_exe_run(buf, NULL);
80 }
81
82 EAPI void
83 e_init_hide(void)
84 {
85    if (init_exe) ecore_exe_terminate(init_exe);
86 }
87
88 EAPI void
89 e_init_title_set(const char *str)
90 {
91    if (title) eina_stringshare_del(title);
92    title = eina_stringshare_add(str);
93 }
94
95 EAPI void
96 e_init_version_set(const char *str)
97 {
98    if (version) eina_stringshare_del(version);
99    version = eina_stringshare_add(str);
100 }
101
102 EAPI void
103 e_init_status_set(const char *str)
104 {
105    if (!init_exe) return;
106 //   printf("---STAT %p %s\n", client, str);
107    if (!client)
108      {
109         stats = eina_list_append(stats, eina_stringshare_add(str));
110         return;
111      }
112 //   printf("---SEND\n");
113    ecore_ipc_client_send(client, E_IPC_DOMAIN_INIT, 1, 0, 0, 0, (void *)str,
114                          strlen(str) + 1);
115    ecore_ipc_client_flush(client);
116 }
117
118 EAPI void
119 e_init_done(void)
120 {
121    undone--;
122    if (undone > 0) return;
123    done = 1;
124    ecore_event_add(E_EVENT_INIT_DONE, NULL, NULL, NULL);
125 //   printf("---DONE %p\n", client);
126    if (!client) return;
127    ecore_ipc_client_send(client, E_IPC_DOMAIN_INIT, 2, 0, 0, 0, NULL, 0);
128    ecore_ipc_client_flush(client);
129 }
130
131 EAPI void
132 e_init_undone(void)
133 {
134    undone++;
135 }
136
137 EAPI void
138 e_init_client_data(Ecore_Ipc_Event_Client_Data *e)
139 {
140 //   printf("---new init client\n");
141    if (!client) client = e->client;
142    if (e->minor == 1)
143      {
144         if (e->data)
145           {
146              int i, num;
147              Ecore_X_Window *initwins;
148
149              num = e->size / sizeof(Ecore_X_Window);
150              initwins = e->data;
151              for (i = 0; i < num; i+= 2)
152                {
153                   Eina_List *l;
154                   E_Manager *man;
155
156                   EINA_LIST_FOREACH(e_manager_list(), l, man)
157                     {
158                        if (man->root == initwins[i + 0])
159                          {
160                             man->initwin = initwins[i + 1];
161                             ecore_x_window_raise(man->initwin);
162                          }
163                     }
164                }
165           }
166         while (stats)
167           {
168              const char *s;
169
170              s = stats->data;
171              stats = eina_list_remove_list(stats, stats);
172 //           printf("---SPOOL %s\n", s);
173              e_init_status_set(s);
174              eina_stringshare_del(s);
175           }
176      }
177    else if (e->minor == 2)
178      {
179         e_config->show_splash = e->ref;
180         e_config_save_queue();
181      }
182    if (done) e_init_done();
183 }
184
185 EAPI void
186 e_init_client_del(Ecore_Ipc_Event_Client_Del *e)
187 {
188 //   printf("---del init client\n");
189    if (e->client == client)
190      {
191         Eina_List *l;
192         E_Manager *man;
193
194         client = NULL;
195         EINA_LIST_FOREACH(e_manager_list(), l, man)
196           {
197              man->initwin = 0;
198           }
199      }
200 }
201
202 EAPI int
203 e_init_count_get(void)
204 {
205    return undone;
206 }
207
208 /* local functions */
209 static Eina_Bool
210 _e_init_cb_exe_event_del(void *data __UNUSED__, int type __UNUSED__, void *event)
211 {
212    Ecore_Exe_Event_Del *ev;
213
214    ev = event;
215    if (ev->exe == init_exe)
216      {
217         /* init exited */
218 //      ecore_exe_free(init_exe);
219         init_exe = NULL;
220      }
221    return ECORE_CALLBACK_RENEW;
222 }