summaryrefslogtreecommitdiff
path: root/src/bin/e_init_main.c
blob: 54bcf2b10924dbe70e3a228e075c4b0f05f1a9c5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <Ecore.h>
#include <Ecore_X.h>
#include <Ecore_Evas.h>
#include <Ecore_Ipc.h>
#include <Evas.h>
#include <Edje.h>

#ifdef EAPI
#undef EAPI
#endif
#ifdef WIN32
# ifdef BUILDING_DLL
#  define EAPI __declspec(dllexport)
# else
#  define EAPI __declspec(dllimport)
# endif
#else
# ifdef __GNUC__
#  if __GNUC__ >= 4
/* BROKEN in gcc 4 on amd64 */
#if 0
#   pragma GCC visibility push(hidden)
#endif
#   define EAPI __attribute__ ((visibility("default")))
#  else
#   define EAPI
#  endif
# else
#  define EAPI
# endif
#endif

#ifdef EINTERN
#undef EINTERN
#endif
#ifdef __GNUC__
# if __GNUC__ >= 4
#  define EINTERN __attribute__ ((visibility("hidden")))
# else
#  define EINTERN
# endif
#else
# define EINTERN
#endif

#define E_TYPEDEFS 1
#include "e_xinerama.h"
#undef E_TYPEDEFS
#include "e_xinerama.h"

EINTERN int e_init_init(void);
EINTERN int e_init_shutdown(void);
EAPI void e_init_show(void);
EAPI void e_init_hide(void);
EAPI void e_init_title_set(const char *str);
EAPI void e_init_version_set(const char *str);
EAPI void e_init_status_set(const char *str);
EAPI void e_init_done(void);

/* local subsystem functions */
static int _e_ipc_init(void);
static Eina_Bool _e_ipc_cb_server_add(void *data, int type, void *event);
static Eina_Bool _e_ipc_cb_server_del(void *data, int type, void *event);
static Eina_Bool _e_ipc_cb_server_data(void *data, int type, void *event);

/* local subsystem globals */
static Ecore_Ipc_Server *_e_ipc_server = NULL;
static const char *theme = NULL;
static int font_hinting = -1;
static const char *title = NULL;
static const char *verstr = NULL;
static Eina_List *fpath = NULL;
static Ecore_X_Window *initwins = NULL;
static int initwins_num = 0;
static Ecore_Ipc_Server *server = NULL;

static Eina_Bool
delayed_ok(void *data __UNUSED__)
{
   kill(getppid(), SIGUSR1);
   return ECORE_CALLBACK_CANCEL;
}

int
main(int argc, char **argv)
{
   int i;
   char *s;
   double scale;

   for (i = 1; i < argc; i++)
     {
	if ((i == 1) && 
	    ((!strcmp(argv[i], "-h")) ||
	     (!strcmp(argv[i], "-help")) ||
	     (!strcmp(argv[i], "--help"))))
	  {
	     printf(
		    "This is an internal tool for Enlightenment.\n"
		    "do not use it.\n"
		    );
	     exit(0);
	  }
	else if (!theme) theme = argv[i];
	else if (font_hinting < 0) font_hinting = atoi(argv[i]);
	else if (!title) title = argv[i];
	else if (!verstr) verstr = argv[i];
	else fpath = eina_list_append(fpath, argv[i]);
     }

   ecore_init();
   ecore_x_init(NULL);
   ecore_app_args_set(argc, (const char **)argv);
   evas_init();
   ecore_evas_init();
   edje_init();
   edje_frametime_set(1.0 / 30.0);
   s = getenv("E_SCALE");
   scale = 1.0;
   if (s) scale = atof(s);
   edje_scale_set(scale);
   ecore_ipc_init();

   if (_e_ipc_init())
     {
	e_init_init();
	e_init_show();
	e_init_title_set(title);
	e_init_version_set(verstr);
	e_init_status_set("");
	ecore_timer_add(0.2, delayed_ok, NULL);
	ecore_main_loop_begin();
     }

   if (_e_ipc_server)
     {
	ecore_ipc_server_del(_e_ipc_server);
	_e_ipc_server = NULL;
     }

   ecore_ipc_shutdown();
   ecore_evas_shutdown();
   edje_shutdown();
   evas_shutdown();
   ecore_x_shutdown();
   ecore_shutdown();

   return 0;
}

/* local subsystem functions */
static int
_e_ipc_init(void)
{
   char *sdir;

   sdir = getenv("E_IPC_SOCKET");
   if (!sdir)
     {
	printf("The E_IPC_SOCKET environment variable is not set. This is\n"
	       "exported by Enlightenment to all processes it launches.\n"
	       "This environment variable must be set and must point to\n"
	       "Enlightenment's IPC socket file (minus port number).\n");
	return 0;
     }
   _e_ipc_server = ecore_ipc_server_connect(ECORE_IPC_LOCAL_SYSTEM, sdir, 0, NULL);
   if (!_e_ipc_server) return 0;

   ecore_event_handler_add(ECORE_IPC_EVENT_SERVER_ADD, _e_ipc_cb_server_add, NULL);
   ecore_event_handler_add(ECORE_IPC_EVENT_SERVER_DEL, _e_ipc_cb_server_del, NULL);
   ecore_event_handler_add(ECORE_IPC_EVENT_SERVER_DATA, _e_ipc_cb_server_data, NULL);

   return 1;
}

static Eina_Bool
_e_ipc_cb_server_add(void *data __UNUSED__, int type __UNUSED__, void *event)
{
   Ecore_Ipc_Event_Server_Add *e;

   e = event;
   server = e->server;
   ecore_ipc_server_send(server,
			 7/*E_IPC_DOMAIN_INIT*/,
			 1/*hello*/,
			 0, 0, 0,
			 initwins, initwins_num * sizeof(Ecore_X_Window));
   ecore_ipc_server_flush(server);
   return ECORE_CALLBACK_PASS_ON;
}

static Eina_Bool
_e_ipc_cb_server_del(void *data __UNUSED__, int type __UNUSED__, void *event __UNUSED__)
{
   /* quit now */
   ecore_main_loop_quit();
   return ECORE_CALLBACK_PASS_ON;
}

static Eina_Bool
_e_ipc_cb_server_data(void *data __UNUSED__, int type __UNUSED__, void *event)
{
   Ecore_Ipc_Event_Server_Data *e;

   e = event;
   if (e->major != 7/*E_IPC_DOMAIN_INIT*/) return ECORE_CALLBACK_PASS_ON;
   switch (e->minor)
     {
      case 1:
	if (e->data) e_init_status_set(e->data);
	break;
      case 2:
	/* quit now */
	e_init_done();
	break;
      default:
	break;
     }
   return ECORE_CALLBACK_PASS_ON;
}

static void _e_init_cb_signal_disable(void *data, Evas_Object *obj, const char *emission, const char *source);
static void _e_init_cb_signal_enable(void *data, Evas_Object *obj, const char *emission, const char *source);
static void _e_init_cb_signal_done_ok(void *data, Evas_Object *obj, const char *emission, const char *source);
static Eina_Bool _e_init_cb_window_configure(void *data, int ev_type, void *ev);
static Eina_Bool _e_init_cb_timeout(void *data);
static Ecore_Evas *_e_init_evas_new(Ecore_X_Window root, int w, int h, Ecore_X_Window *winret);

/* local subsystem globals */
static Ecore_X_Window _e_init_root_win = 0;
static Ecore_X_Window _e_init_win = 0;
static Ecore_Evas *_e_init_ecore_evas = NULL;
static Evas *_e_init_evas = NULL;
static Evas_Object *_e_init_object = NULL;
static Ecore_Event_Handler *_e_init_configure_handler = NULL;
static Ecore_Timer *_e_init_timeout_timer = NULL;

/* externally accessible functions */
EINTERN int
e_init_init(void)
{
   Ecore_X_Window root, *roots;
   Evas_Object *o;
   Eina_List *l, *screens;
   int i, num, w, h;
   const char *s;

   e_xinerama_init();

   _e_init_configure_handler = 
     ecore_event_handler_add(ECORE_X_EVENT_WINDOW_CONFIGURE, 
			     _e_init_cb_window_configure, NULL);

   num = 0;
   roots = ecore_x_window_root_list(&num);
   if ((!roots) || (num <= 0)) return 0;
   root = roots[0];
   _e_init_root_win = root;

   s = theme;
   initwins = malloc(num * 2 * sizeof(Ecore_X_Window));
   initwins_num = num * 2;

   /* extra root windows/screens */
   for (i = 1; i < num; i++)
     {
	ecore_x_window_size_get(roots[i], &w, &h);
	_e_init_ecore_evas = _e_init_evas_new(roots[i], w, h, &_e_init_win);
	_e_init_evas = ecore_evas_get(_e_init_ecore_evas);
	initwins[(i * 2) + 0] = roots[i];
	initwins[(i * 2) + 1] = _e_init_win;

	o = edje_object_add(_e_init_evas);
	edje_object_file_set(o, s, "e/init/extra_screen");
	evas_object_move(o, 0, 0);
	evas_object_resize(o, w, h);
	evas_object_show(o);
     }

   /* primary screen/root */
   ecore_x_window_size_get(root, &w, &h);
   _e_init_ecore_evas = _e_init_evas_new(root, w, h, &_e_init_win);
   _e_init_evas = ecore_evas_get(_e_init_ecore_evas);
   initwins[0] = root;
   initwins[1] = _e_init_win;

   /* look at xinerama asto how to slice this up */
   screens = (Eina_List *)e_xinerama_screens_get();
   if (screens)
     {
	E_Screen *scr;

	EINA_LIST_FOREACH(screens, l, scr)
	  {
	     o = edje_object_add(_e_init_evas);
	     if (l == screens)
	       {
		  edje_object_file_set(o, s, "e/init/splash");
		  _e_init_object = o;
	       }
	     else
	       edje_object_file_set(o, s, "e/init/extra_screen");
	     evas_object_move(o, scr->x, scr->y);
	     evas_object_resize(o, scr->w, scr->h);
	     evas_object_show(o);
	  }
     }
   else
     {
	o = edje_object_add(_e_init_evas);
	edje_object_file_set(o, s, "e/init/splash");
	_e_init_object = o;
	evas_object_move(o, 0, 0);
	evas_object_resize(o, w, h);
	evas_object_show(o);
     }

   edje_object_part_text_set(_e_init_object, "e.text.disable_text", 
			     "Disable splash screen");
   edje_object_signal_callback_add(_e_init_object, "e,action,init,disable", "e",
				   _e_init_cb_signal_disable, NULL);
   edje_object_signal_callback_add(_e_init_object, "e,action,init,enable", "e",
				   _e_init_cb_signal_enable, NULL);
   edje_object_signal_callback_add(_e_init_object, "e,state,done_ok", "e",
				   _e_init_cb_signal_done_ok, NULL);
   free(roots);

   _e_init_timeout_timer = ecore_timer_add(240.0, _e_init_cb_timeout, NULL);
   return 1;
}

EINTERN int
e_init_shutdown(void)
{
   if (_e_init_configure_handler) 
     ecore_event_handler_del(_e_init_configure_handler);
   _e_init_configure_handler = NULL;
   e_init_hide();
   return 1;
}

EAPI void
e_init_show(void)
{
   if (!_e_init_ecore_evas) return;
   ecore_evas_raise(_e_init_ecore_evas);
   ecore_evas_show(_e_init_ecore_evas);
}

EAPI void
e_init_hide(void)
{
   if (!_e_init_ecore_evas) return;
   ecore_evas_hide(_e_init_ecore_evas);
   evas_object_del(_e_init_object);
   ecore_evas_free(_e_init_ecore_evas);
   _e_init_ecore_evas = NULL;
   _e_init_evas = NULL;
   _e_init_win = 0;
   _e_init_object = NULL;
}

EAPI void
e_init_title_set(const char *str)
{
   if (!_e_init_object) return;
   edje_object_part_text_set(_e_init_object, "e.text.title", str);
}

EAPI void
e_init_version_set(const char *str)
{
   if (!_e_init_object) return;
   edje_object_part_text_set(_e_init_object, "e.text.version", str);
}

EAPI void
e_init_status_set(const char *str)
{
   if (!_e_init_object) return;
   edje_object_part_text_set(_e_init_object, "e.text.status", str);
}

EAPI void
e_init_done(void)
{
   if (!_e_init_object) return;
   edje_object_signal_emit(_e_init_object, "e,state,done", "e");
   if (_e_init_timeout_timer) ecore_timer_del(_e_init_timeout_timer);
   _e_init_timeout_timer = ecore_timer_add(60.0, _e_init_cb_timeout, NULL);
}


static void
_e_init_cb_signal_disable(void *data __UNUSED__, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
{
   if (!server) return;
   ecore_ipc_server_send(server,
			 7/*E_IPC_DOMAIN_INIT*/,
			 2/*set splash*/,
			 0, 0, 0,
			 NULL, 0);
   ecore_ipc_server_flush(server);
}

static void
_e_init_cb_signal_enable(void *data __UNUSED__, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
{
   if (!server) return;
   ecore_ipc_server_send(server,
			 7/*E_IPC_DOMAIN_INIT*/,
			 2/*set splash*/,
			 1, 0, 0,
			 NULL, 0);
   ecore_ipc_server_flush(server);
}

static void
_e_init_cb_signal_done_ok(void *data __UNUSED__, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
{
   e_init_hide();
   if (_e_init_timeout_timer)
     {
	ecore_timer_del(_e_init_timeout_timer);
	_e_init_timeout_timer = NULL;
     }
   ecore_main_loop_quit();
}

static Eina_Bool
_e_init_cb_window_configure(void *data __UNUSED__, int ev_type __UNUSED__, void *ev)
{
   Ecore_X_Event_Window_Configure *e;

   e = ev;
   /* really simple - don't handle xinerama - because this event will only
    * happen in single head */
   if (e->win != _e_init_root_win) return ECORE_CALLBACK_PASS_ON;
   ecore_evas_resize(_e_init_ecore_evas, e->w, e->h);
   evas_object_resize(_e_init_object, e->w, e->h);
   return ECORE_CALLBACK_PASS_ON;
}

static Eina_Bool
_e_init_cb_timeout(void *data __UNUSED__)
{
   e_init_hide();
   _e_init_timeout_timer = NULL;
   ecore_main_loop_quit();
   return ECORE_CALLBACK_CANCEL;
}

static Ecore_Evas *
_e_init_evas_new(Ecore_X_Window root, int w, int h, Ecore_X_Window *winret)
{
   Ecore_Evas *ee = NULL;
   Evas *e;
   Eina_List *l;
   const char *path;

   ee = ecore_evas_software_x11_new(NULL, root, 0, 0, w, h);
   ecore_evas_override_set(ee, 1);
   ecore_evas_software_x11_direct_resize_set(ee, 1);
   *winret = ecore_evas_software_x11_window_get(ee);

   e = ecore_evas_get(ee);

   evas_image_cache_set(e, 4096 * 1024);
   evas_font_cache_set(e, 512 * 1024);

   EINA_LIST_FOREACH(fpath, l, path) 
     evas_font_path_append(e, path);

   if (font_hinting == 0)
     {
	if (evas_font_hinting_can_hint(e, EVAS_FONT_HINTING_BYTECODE))
	  evas_font_hinting_set(e, EVAS_FONT_HINTING_BYTECODE);
	else if (evas_font_hinting_can_hint(e, EVAS_FONT_HINTING_AUTO))
	  evas_font_hinting_set(e, EVAS_FONT_HINTING_AUTO);
	else
	  evas_font_hinting_set(e, EVAS_FONT_HINTING_NONE);
     }
   else if (font_hinting == 1)
     {
	if (evas_font_hinting_can_hint(e, EVAS_FONT_HINTING_AUTO))
	  evas_font_hinting_set(e, EVAS_FONT_HINTING_AUTO);
	else
	  evas_font_hinting_set(e, EVAS_FONT_HINTING_NONE);
     }
   else if (font_hinting == 2)
     evas_font_hinting_set(e, EVAS_FONT_HINTING_NONE);

   ecore_evas_name_class_set(ee, "E", "Init_Window");
   ecore_evas_title_set(ee, "Enlightenment Init");

   ecore_evas_raise(ee);
   ecore_evas_show(ee);

   return ee;
}