diff options
author | David Walter Seikel | 2013-01-13 17:29:19 +1000 |
---|---|---|
committer | David Walter Seikel | 2013-01-13 17:29:19 +1000 |
commit | 07274513e984f0b5544586c74508ccd16e7dcafa (patch) | |
tree | b32ff2a9136fbc1a4a6a0ed1e4d79cde0f5f16d9 /libraries/edje/src/bin/edje_player.c | |
parent | Added Irrlicht 1.8, but without all the Windows binaries. (diff) | |
download | SledjHamr-07274513e984f0b5544586c74508ccd16e7dcafa.zip SledjHamr-07274513e984f0b5544586c74508ccd16e7dcafa.tar.gz SledjHamr-07274513e984f0b5544586c74508ccd16e7dcafa.tar.bz2 SledjHamr-07274513e984f0b5544586c74508ccd16e7dcafa.tar.xz |
Remove EFL, since it's been released now.
Diffstat (limited to 'libraries/edje/src/bin/edje_player.c')
-rw-r--r-- | libraries/edje/src/bin/edje_player.c | 789 |
1 files changed, 0 insertions, 789 deletions
diff --git a/libraries/edje/src/bin/edje_player.c b/libraries/edje/src/bin/edje_player.c deleted file mode 100644 index 208fbb4..0000000 --- a/libraries/edje/src/bin/edje_player.c +++ /dev/null | |||
@@ -1,789 +0,0 @@ | |||
1 | #ifdef HAVE_CONFIG_H | ||
2 | #include <config.h> | ||
3 | #endif | ||
4 | |||
5 | #include <stdio.h> | ||
6 | #include <string.h> | ||
7 | #include <stdlib.h> | ||
8 | #include <errno.h> | ||
9 | #include <unistd.h> | ||
10 | #include <fcntl.h> | ||
11 | #include <ctype.h> | ||
12 | |||
13 | #ifdef HAVE_EVIL | ||
14 | # include <Evil.h> | ||
15 | #endif | ||
16 | |||
17 | #include <Evas.h> | ||
18 | #include <Ecore.h> | ||
19 | #include <Ecore_Getopt.h> | ||
20 | #include <Ecore_Evas.h> | ||
21 | #include <Edje.h> | ||
22 | |||
23 | struct opts { | ||
24 | char *file; | ||
25 | char *group; | ||
26 | Eina_Bool list_groups; | ||
27 | char *engine; | ||
28 | Eina_Rectangle size; | ||
29 | unsigned char color[3]; | ||
30 | Eina_Bool borderless; | ||
31 | Eina_Bool sticky; | ||
32 | Eina_Bool shaped; | ||
33 | Eina_Bool alpha; | ||
34 | Eina_Bool print; | ||
35 | Eina_Bool slave_mode; | ||
36 | double scale; | ||
37 | char *title; | ||
38 | }; | ||
39 | |||
40 | static Ecore_Evas *win; | ||
41 | |||
42 | static void | ||
43 | _win_title_set(const char *group, const char *file) | ||
44 | { | ||
45 | char buf[1024]; | ||
46 | snprintf(buf, sizeof(buf), "Edje_Player - %s of %s", group, file); | ||
47 | ecore_evas_title_set(win, buf); | ||
48 | } | ||
49 | |||
50 | static char * | ||
51 | _slave_mode_tok(char **p_arg) | ||
52 | { | ||
53 | char *s, *e; | ||
54 | Eina_Bool is_quoted; | ||
55 | |||
56 | if (!*p_arg) return NULL; | ||
57 | |||
58 | s = *p_arg; | ||
59 | while (isspace(*s)) | ||
60 | s++; | ||
61 | |||
62 | if (*s == '\0') | ||
63 | { | ||
64 | *p_arg = NULL; | ||
65 | return NULL; | ||
66 | } | ||
67 | else if (*s == '"') | ||
68 | { | ||
69 | is_quoted = EINA_TRUE; | ||
70 | s++; | ||
71 | *p_arg = s; | ||
72 | } | ||
73 | else | ||
74 | { | ||
75 | is_quoted = EINA_FALSE; | ||
76 | *p_arg = s; | ||
77 | } | ||
78 | |||
79 | for (e = s; *e != '\0'; e++) | ||
80 | { | ||
81 | if ((!is_quoted) && (isspace(*e))) | ||
82 | break; | ||
83 | else if ((is_quoted) && (*e == '"')) | ||
84 | break; | ||
85 | } | ||
86 | |||
87 | if (*e == '\0') return NULL; | ||
88 | |||
89 | *e = '\0'; | ||
90 | return e + 1; | ||
91 | } | ||
92 | |||
93 | static void | ||
94 | _slave_mode_signal(Evas_Object *edje, char *args) | ||
95 | { | ||
96 | char *emission, *source; | ||
97 | |||
98 | emission = args; | ||
99 | source = _slave_mode_tok(&emission); | ||
100 | _slave_mode_tok(&source); | ||
101 | |||
102 | if ((!emission) || (!source)) | ||
103 | { | ||
104 | fputs("ERROR: Invalid command arguments.\n", stderr); | ||
105 | return; | ||
106 | } | ||
107 | |||
108 | edje_object_signal_emit(edje, emission, source); | ||
109 | } | ||
110 | |||
111 | static void | ||
112 | _slave_mode_info(Evas_Object *edje, char *args) | ||
113 | { | ||
114 | _slave_mode_tok(&args); | ||
115 | |||
116 | if (!args) | ||
117 | { | ||
118 | fputs("ERROR: Invalid command arguments.\n", stderr); | ||
119 | return; | ||
120 | } | ||
121 | |||
122 | if (!edje_object_part_exists(edje, args)) | ||
123 | { | ||
124 | printf("INFO: \"%s\" does not exist.\n", args); | ||
125 | } | ||
126 | else | ||
127 | { | ||
128 | Evas_Coord x, y, w, h; | ||
129 | edje_object_part_geometry_get(edje, args, &x, &y, &w, &h); | ||
130 | printf("INFO: \"%s\" %d,%d,%d,%d\n", args, x, y, w, h); | ||
131 | } | ||
132 | } | ||
133 | |||
134 | static void | ||
135 | _slave_mode_quit(Evas_Object *edje __UNUSED__, char *args __UNUSED__) | ||
136 | { | ||
137 | puts("Bye!"); | ||
138 | ecore_main_loop_quit(); | ||
139 | } | ||
140 | |||
141 | static void | ||
142 | _slave_mode_help(Evas_Object *edje __UNUSED__, char *args __UNUSED__) | ||
143 | { | ||
144 | puts("Help:\n" | ||
145 | "One command per line, arguments separated by space. Strings may have " | ||
146 | "spaces if enclosed in quotes (\").\n" | ||
147 | "\n" | ||
148 | "\t<command> [arguments]\n" | ||
149 | "\n" | ||
150 | "Available commands:\n" | ||
151 | "\tsignal <emission> <source>\n" | ||
152 | "\t sends a signal to edje\n" | ||
153 | "\tinfo <part>\n" | ||
154 | "\t Print part geometry: <x>,<y>,<w>,<h>\n" | ||
155 | "\tquit\n" | ||
156 | "\t exit edje player.\n" | ||
157 | "\thelp\n" | ||
158 | "\t shows this message.\n"); | ||
159 | /* | ||
160 | * Extension ideas (are they useful?): | ||
161 | * - message: send a message | ||
162 | * - data: show data value | ||
163 | * - color_class: set color class values (maybe also list?) | ||
164 | * - text_class: set text class values (maybe also list?) | ||
165 | * - play_set: change play state | ||
166 | * - animation_set: change animation state | ||
167 | */ | ||
168 | } | ||
169 | |||
170 | struct slave_cmd | ||
171 | { | ||
172 | const char *cmd; | ||
173 | void (*func)(Evas_Object *edje, char *args); | ||
174 | } _slave_mode_commands[] = { | ||
175 | {"signal", _slave_mode_signal}, | ||
176 | {"info", _slave_mode_info}, | ||
177 | {"quit", _slave_mode_quit}, | ||
178 | {"help", _slave_mode_help}, | ||
179 | {NULL, NULL} | ||
180 | }; | ||
181 | |||
182 | static Eina_Bool | ||
183 | _slave_mode(void *data, Ecore_Fd_Handler *fd_handler) | ||
184 | { | ||
185 | Evas_Object *edje = data; | ||
186 | char buf[1024], *p; | ||
187 | const struct slave_cmd *itr; | ||
188 | size_t len; | ||
189 | |||
190 | if (ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_ERROR)) | ||
191 | { | ||
192 | fputs("ERROR: error on stdin! Exit.\n", stderr); | ||
193 | ecore_main_loop_quit(); | ||
194 | return ECORE_CALLBACK_CANCEL; | ||
195 | } | ||
196 | if (!ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_READ)) | ||
197 | return ECORE_CALLBACK_RENEW; | ||
198 | |||
199 | if (!fgets(buf, sizeof(buf), stdin)) | ||
200 | { | ||
201 | fputs("ERROR: end of stdin! Exit.\n", stderr); | ||
202 | ecore_main_loop_quit(); | ||
203 | return ECORE_CALLBACK_CANCEL; | ||
204 | } | ||
205 | |||
206 | len = strlen(buf); | ||
207 | if (len < 1) | ||
208 | { | ||
209 | fputs("ERROR: no input! Try: help\n", stderr); | ||
210 | return ECORE_CALLBACK_RENEW; | ||
211 | } | ||
212 | if (buf[len - 1] == '\n') | ||
213 | { | ||
214 | len--; | ||
215 | buf[len] = '\0'; | ||
216 | } | ||
217 | |||
218 | p = strchr(buf, ' '); | ||
219 | if (p) | ||
220 | { | ||
221 | *p = '\0'; | ||
222 | p++; | ||
223 | |||
224 | while (isspace(*p)) | ||
225 | p++; | ||
226 | if (*p == '\0') | ||
227 | p = NULL; | ||
228 | |||
229 | if (p) | ||
230 | { | ||
231 | char *q = p + strlen(p) - 1; | ||
232 | while (isspace(*q)) | ||
233 | { | ||
234 | *q = '\0'; | ||
235 | q--; | ||
236 | } | ||
237 | } | ||
238 | } | ||
239 | |||
240 | for (itr = _slave_mode_commands; itr->cmd; itr++) | ||
241 | { | ||
242 | if (strcmp(itr->cmd, buf) == 0) | ||
243 | { | ||
244 | itr->func(edje, p); | ||
245 | break; | ||
246 | } | ||
247 | } | ||
248 | |||
249 | return ECORE_CALLBACK_RENEW; | ||
250 | } | ||
251 | |||
252 | static void | ||
253 | _print_signal(void *data __UNUSED__, Evas_Object *o __UNUSED__, const char *emission, const char *source) | ||
254 | { | ||
255 | printf("SIGNAL: \"%s\" \"%s\"\n", emission, source); | ||
256 | } | ||
257 | |||
258 | static void | ||
259 | _print_message(void *data __UNUSED__, Evas_Object *edje __UNUSED__, Edje_Message_Type type, int id, void *msg) | ||
260 | { | ||
261 | const char *typestr; | ||
262 | char buf[64]; | ||
263 | |||
264 | switch (type) | ||
265 | { | ||
266 | case EDJE_MESSAGE_NONE: | ||
267 | typestr = "NONE"; | ||
268 | break; | ||
269 | case EDJE_MESSAGE_SIGNAL: | ||
270 | typestr = "SIGNAL"; | ||
271 | break; | ||
272 | case EDJE_MESSAGE_STRING: | ||
273 | typestr = "STRING"; | ||
274 | break; | ||
275 | case EDJE_MESSAGE_INT: | ||
276 | typestr = "INT"; | ||
277 | break; | ||
278 | case EDJE_MESSAGE_FLOAT: | ||
279 | typestr = "FLOAT"; | ||
280 | break; | ||
281 | case EDJE_MESSAGE_STRING_SET: | ||
282 | typestr = "STRING_SET"; | ||
283 | break; | ||
284 | case EDJE_MESSAGE_INT_SET: | ||
285 | typestr = "INT_SET"; | ||
286 | break; | ||
287 | case EDJE_MESSAGE_FLOAT_SET: | ||
288 | typestr = "FLOAT_SET"; | ||
289 | break; | ||
290 | case EDJE_MESSAGE_STRING_INT: | ||
291 | typestr = "STRING_INT"; | ||
292 | break; | ||
293 | case EDJE_MESSAGE_STRING_FLOAT: | ||
294 | typestr = "STRING_FLOAT"; | ||
295 | break; | ||
296 | case EDJE_MESSAGE_STRING_INT_SET: | ||
297 | typestr = "INT_SET"; | ||
298 | break; | ||
299 | case EDJE_MESSAGE_STRING_FLOAT_SET: | ||
300 | typestr = "FLOAT_SET"; | ||
301 | break; | ||
302 | default: | ||
303 | snprintf(buf, sizeof(buf), "UNKNOWN(%d)", type); | ||
304 | typestr = buf; | ||
305 | } | ||
306 | |||
307 | printf("MESSAGE: type=%s, id=%d", typestr, id); | ||
308 | |||
309 | switch (type) | ||
310 | { | ||
311 | case EDJE_MESSAGE_NONE: break; | ||
312 | case EDJE_MESSAGE_SIGNAL: break; | ||
313 | case EDJE_MESSAGE_STRING: | ||
314 | { | ||
315 | Edje_Message_String *m = msg; | ||
316 | printf(" \"%s\"", m->str); | ||
317 | } | ||
318 | break; | ||
319 | case EDJE_MESSAGE_INT: | ||
320 | { | ||
321 | Edje_Message_Int *m = msg; | ||
322 | printf(" %d", m->val); | ||
323 | } | ||
324 | break; | ||
325 | case EDJE_MESSAGE_FLOAT: | ||
326 | { | ||
327 | Edje_Message_Float *m = msg; | ||
328 | printf(" %f", m->val); | ||
329 | } | ||
330 | break; | ||
331 | case EDJE_MESSAGE_STRING_SET: | ||
332 | { | ||
333 | Edje_Message_String_Set *m = msg; | ||
334 | int i; | ||
335 | for (i = 0; i < m->count; i++) | ||
336 | printf(" \"%s\"", m->str[i]); | ||
337 | } | ||
338 | break; | ||
339 | case EDJE_MESSAGE_INT_SET: | ||
340 | { | ||
341 | Edje_Message_Int_Set *m = msg; | ||
342 | int i; | ||
343 | for (i = 0; i < m->count; i++) | ||
344 | printf(" %d", m->val[i]); | ||
345 | } | ||
346 | break; | ||
347 | case EDJE_MESSAGE_FLOAT_SET: | ||
348 | { | ||
349 | Edje_Message_Float_Set *m = msg; | ||
350 | int i; | ||
351 | for (i = 0; i < m->count; i++) | ||
352 | printf(" %f", m->val[i]); | ||
353 | } | ||
354 | break; | ||
355 | case EDJE_MESSAGE_STRING_INT: | ||
356 | { | ||
357 | Edje_Message_String_Int *m = msg; | ||
358 | printf(" \"%s\" %d", m->str, m->val); | ||
359 | } | ||
360 | break; | ||
361 | case EDJE_MESSAGE_STRING_FLOAT: | ||
362 | { | ||
363 | Edje_Message_String_Float *m = msg; | ||
364 | printf(" \"%s\" %f", m->str, m->val); | ||
365 | } | ||
366 | break; | ||
367 | case EDJE_MESSAGE_STRING_INT_SET: | ||
368 | { | ||
369 | Edje_Message_String_Int_Set *m = msg; | ||
370 | int i; | ||
371 | printf(" \"%s\"", m->str); | ||
372 | for (i = 0; i < m->count; i++) | ||
373 | printf(" %d", m->val[i]); | ||
374 | } | ||
375 | break; | ||
376 | case EDJE_MESSAGE_STRING_FLOAT_SET: | ||
377 | { | ||
378 | Edje_Message_String_Float_Set *m = msg; | ||
379 | int i; | ||
380 | printf(" \"%s\"", m->str); | ||
381 | for (i = 0; i < m->count; i++) | ||
382 | printf(" %f", m->val[i]); | ||
383 | } | ||
384 | break; | ||
385 | default: | ||
386 | break; | ||
387 | } | ||
388 | |||
389 | putchar('\n'); | ||
390 | } | ||
391 | |||
392 | static void | ||
393 | _reset_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *stack, void *event_info __UNUSED__) | ||
394 | { | ||
395 | Evas_Coord minw, minh; | ||
396 | Evas_Object *edje = data; | ||
397 | |||
398 | edje_object_size_min_get(edje, &minw, &minh); | ||
399 | if ((minw <= 0) && (minh <= 0)) | ||
400 | edje_object_size_min_calc(edje, &minw, &minh); | ||
401 | |||
402 | evas_object_size_hint_min_set(stack, minw, minh); | ||
403 | } | ||
404 | |||
405 | static void | ||
406 | _key_down(void *data, Evas *e __UNUSED__, Evas_Object *stack __UNUSED__, void *event_info) | ||
407 | { | ||
408 | Evas_Event_Key_Down *ev = event_info; | ||
409 | struct opts *opts = data; | ||
410 | |||
411 | if ((!strcmp(ev->keyname, "equal")) || | ||
412 | (!strcmp(ev->keyname, "plus"))) | ||
413 | opts->scale += 0.1; | ||
414 | else if ((!strcmp(ev->keyname, "minus")) || | ||
415 | (!strcmp(ev->keyname, "underscore"))) | ||
416 | opts->scale -= 0.1; | ||
417 | else if ((!strcmp(ev->keyname, "0"))) | ||
418 | opts->scale = 1.0; | ||
419 | if (opts->scale < 0.1) opts->scale = 0.1; | ||
420 | else if (opts->scale > 10.0) opts->scale = 1.0; | ||
421 | edje_scale_set(opts->scale); | ||
422 | } | ||
423 | |||
424 | static Evas_Object * | ||
425 | _create_stack(Evas *evas, const struct opts *opts) | ||
426 | { | ||
427 | Evas_Object *stack = evas_object_box_add(evas); | ||
428 | if (!stack) | ||
429 | { | ||
430 | fputs("ERROR: could not create object stack (box).\n", stderr); | ||
431 | return NULL; | ||
432 | } | ||
433 | evas_object_box_layout_set(stack, evas_object_box_layout_stack, NULL, NULL); | ||
434 | evas_object_resize(stack, opts->size.w, opts->size.h); | ||
435 | evas_object_size_hint_weight_set(stack, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); | ||
436 | evas_object_size_hint_align_set(stack, EVAS_HINT_FILL, EVAS_HINT_FILL); | ||
437 | evas_object_show(stack); | ||
438 | return stack; | ||
439 | } | ||
440 | |||
441 | static Evas_Object * | ||
442 | _create_bg(Evas *evas, const struct opts *opts) | ||
443 | { | ||
444 | const unsigned char *color = opts->color; | ||
445 | Evas_Object *bg = evas_object_rectangle_add(evas); | ||
446 | if (!bg) | ||
447 | { | ||
448 | fputs("ERROR: could not create background.\n", stderr); | ||
449 | return NULL; | ||
450 | } | ||
451 | evas_object_resize(bg, opts->size.w, opts->size.h); | ||
452 | evas_object_color_set(bg, color[0], color[1], color[2], 255); | ||
453 | evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); | ||
454 | evas_object_size_hint_align_set(bg, EVAS_HINT_FILL, EVAS_HINT_FILL); | ||
455 | evas_object_show(bg); | ||
456 | return bg; | ||
457 | } | ||
458 | |||
459 | static Eina_Bool | ||
460 | _edje_load_or_show_error(Evas_Object *edje, const char *file, const char *group) | ||
461 | { | ||
462 | const char *errmsg; | ||
463 | int err; | ||
464 | |||
465 | if (edje_object_file_set(edje, file, group)) | ||
466 | { | ||
467 | evas_object_focus_set(edje, EINA_TRUE); | ||
468 | return EINA_TRUE; | ||
469 | } | ||
470 | |||
471 | err = edje_object_load_error_get(edje); | ||
472 | errmsg = edje_load_error_str(err); | ||
473 | fprintf(stderr, "ERROR: could not load edje file '%s', group '%s': %s\n", | ||
474 | file, group, errmsg); | ||
475 | return EINA_FALSE; | ||
476 | } | ||
477 | |||
478 | static Evas_Object * | ||
479 | _create_edje(Evas *evas, const struct opts *opts) | ||
480 | { | ||
481 | Evas_Coord minw, minh, maxw, maxh; | ||
482 | Evas_Object *edje = edje_object_add(evas); | ||
483 | if (!edje) | ||
484 | { | ||
485 | fputs("ERROR: could not create edje.\n", stderr); | ||
486 | return NULL; | ||
487 | } | ||
488 | |||
489 | if (opts->group) | ||
490 | { | ||
491 | if (!_edje_load_or_show_error(edje, opts->file, opts->group)) | ||
492 | { | ||
493 | evas_object_del(edje); | ||
494 | return NULL; | ||
495 | } | ||
496 | if (!opts->title) _win_title_set(opts->group, opts->file); | ||
497 | } | ||
498 | else | ||
499 | { | ||
500 | if (edje_file_group_exists(opts->file, "main")) | ||
501 | { | ||
502 | if (!_edje_load_or_show_error(edje, opts->file, "main")) | ||
503 | { | ||
504 | evas_object_del(edje); | ||
505 | return NULL; | ||
506 | } | ||
507 | if (!opts->title) _win_title_set("main", opts->file); | ||
508 | } | ||
509 | else | ||
510 | { | ||
511 | Eina_List *groups = edje_file_collection_list(opts->file); | ||
512 | const char *group; | ||
513 | if (!groups) | ||
514 | { | ||
515 | fprintf(stderr, "ERROR: file '%s' has no groups!\n", | ||
516 | opts->file); | ||
517 | evas_object_del(edje); | ||
518 | return NULL; | ||
519 | } | ||
520 | group = groups->data; | ||
521 | if (!_edje_load_or_show_error(edje, opts->file, group)) | ||
522 | { | ||
523 | edje_file_collection_list_free(groups); | ||
524 | evas_object_del(edje); | ||
525 | return NULL; | ||
526 | } | ||
527 | if (!opts->title) _win_title_set(group, opts->file); | ||
528 | edje_file_collection_list_free(groups); | ||
529 | } | ||
530 | } | ||
531 | |||
532 | edje_object_size_max_get(edje, &maxw, &maxh); | ||
533 | edje_object_size_min_get(edje, &minw, &minh); | ||
534 | if ((minw <= 0) && (minh <= 0)) | ||
535 | edje_object_size_min_calc(edje, &minw, &minh); | ||
536 | |||
537 | evas_object_size_hint_max_set(edje, maxw, maxh); | ||
538 | evas_object_size_hint_min_set(edje, minw, minh); | ||
539 | |||
540 | evas_object_size_hint_weight_set(edje, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); | ||
541 | evas_object_size_hint_align_set(edje, EVAS_HINT_FILL, EVAS_HINT_FILL); | ||
542 | evas_object_show(edje); | ||
543 | |||
544 | return edje; | ||
545 | } | ||
546 | |||
547 | static unsigned char _parse_color(__UNUSED__ const Ecore_Getopt *parser, __UNUSED__ const Ecore_Getopt_Desc *desc, const char *str, __UNUSED__ void *data, Ecore_Getopt_Value *storage) | ||
548 | { | ||
549 | unsigned char *color = (unsigned char *)storage->ptrp; | ||
550 | |||
551 | if (sscanf(str, "%hhu,%hhu,%hhu", color, color + 1, color + 2) != 3) | ||
552 | { | ||
553 | fprintf(stderr, "ERROR: incorrect color value '%s'\n", str); | ||
554 | return 0; | ||
555 | } | ||
556 | |||
557 | return 1; | ||
558 | } | ||
559 | |||
560 | static void _cb_delete(__UNUSED__ Ecore_Evas *ee) | ||
561 | { | ||
562 | ecore_main_loop_quit(); | ||
563 | } | ||
564 | |||
565 | const Ecore_Getopt optdesc = { | ||
566 | "edje_player", | ||
567 | "%prog [options] <filename.edj>", | ||
568 | PACKAGE_VERSION, | ||
569 | "(C) 2010 Enlightenment", | ||
570 | "BSD with advertisement clause", | ||
571 | "Simple application to view edje files.", | ||
572 | 0, | ||
573 | { | ||
574 | ECORE_GETOPT_STORE_STR | ||
575 | ('g', "group", "The edje group to view (defaults to 'main')."), | ||
576 | ECORE_GETOPT_STORE_TRUE | ||
577 | ('G', "list-groups", "The groups in the given file."), | ||
578 | ECORE_GETOPT_STORE_STR | ||
579 | ('e', "engine", "The Ecore-Evas engine to use (see --list-engines)"), | ||
580 | ECORE_GETOPT_CALLBACK_NOARGS | ||
581 | ('E', "list-engines", "list Ecore-Evas engines", | ||
582 | ecore_getopt_callback_ecore_evas_list_engines, NULL), | ||
583 | ECORE_GETOPT_CALLBACK_ARGS | ||
584 | ('Z', "size", "size to use in wxh form.", "WxH", | ||
585 | ecore_getopt_callback_size_parse, NULL), | ||
586 | ECORE_GETOPT_CALLBACK_ARGS | ||
587 | ('c', "bg-color", "Color of the background (if not shaped or alpha)", | ||
588 | "RRGGBB", _parse_color, NULL), | ||
589 | ECORE_GETOPT_STORE_TRUE | ||
590 | ('b', "borderless", "Display window without border."), | ||
591 | ECORE_GETOPT_STORE_TRUE | ||
592 | ('y', "sticky", "Display window sticky."), | ||
593 | ECORE_GETOPT_STORE_TRUE | ||
594 | ('s', "shaped", "Display window shaped."), | ||
595 | ECORE_GETOPT_STORE_TRUE | ||
596 | ('a', "alpha", "Display window with alpha channel " | ||
597 | "(needs composite manager!)"), | ||
598 | ECORE_GETOPT_STORE_STR | ||
599 | ('t', "title", "Define the window title string"), | ||
600 | ECORE_GETOPT_STORE_TRUE | ||
601 | ('p', "print", "Print signals and messages to stdout"), | ||
602 | ECORE_GETOPT_STORE_TRUE | ||
603 | ('S', "slave-mode", "Listen for commands on stdin"), | ||
604 | ECORE_GETOPT_STORE_DOUBLE | ||
605 | ('z', "scale", "Set scale factor"), | ||
606 | ECORE_GETOPT_LICENSE('L', "license"), | ||
607 | ECORE_GETOPT_COPYRIGHT('C', "copyright"), | ||
608 | ECORE_GETOPT_VERSION('V', "version"), | ||
609 | ECORE_GETOPT_HELP('h', "help"), | ||
610 | ECORE_GETOPT_SENTINEL | ||
611 | } | ||
612 | }; | ||
613 | |||
614 | int main(int argc, char **argv) | ||
615 | { | ||
616 | Evas *evas; | ||
617 | Evas_Object *stack, *edje; | ||
618 | struct opts opts; | ||
619 | Eina_Bool quit_option = EINA_FALSE; | ||
620 | int args; | ||
621 | Ecore_Getopt_Value values[] = { | ||
622 | ECORE_GETOPT_VALUE_STR(opts.group), | ||
623 | ECORE_GETOPT_VALUE_BOOL(opts.list_groups), | ||
624 | ECORE_GETOPT_VALUE_STR(opts.engine), | ||
625 | ECORE_GETOPT_VALUE_BOOL(quit_option), | ||
626 | ECORE_GETOPT_VALUE_PTR_CAST(opts.size), | ||
627 | ECORE_GETOPT_VALUE_PTR_CAST(opts.color), | ||
628 | ECORE_GETOPT_VALUE_BOOL(opts.borderless), | ||
629 | ECORE_GETOPT_VALUE_BOOL(opts.sticky), | ||
630 | ECORE_GETOPT_VALUE_BOOL(opts.shaped), | ||
631 | ECORE_GETOPT_VALUE_BOOL(opts.alpha), | ||
632 | ECORE_GETOPT_VALUE_STR(opts.title), | ||
633 | ECORE_GETOPT_VALUE_BOOL(opts.print), | ||
634 | ECORE_GETOPT_VALUE_BOOL(opts.slave_mode), | ||
635 | ECORE_GETOPT_VALUE_DOUBLE(opts.scale), | ||
636 | ECORE_GETOPT_VALUE_BOOL(quit_option), | ||
637 | ECORE_GETOPT_VALUE_BOOL(quit_option), | ||
638 | ECORE_GETOPT_VALUE_BOOL(quit_option), | ||
639 | ECORE_GETOPT_VALUE_BOOL(quit_option), | ||
640 | ECORE_GETOPT_VALUE_NONE | ||
641 | }; | ||
642 | |||
643 | memset(&opts, 0, sizeof(opts)); | ||
644 | opts.scale = 1.0; | ||
645 | |||
646 | if (!ecore_evas_init()) | ||
647 | return EXIT_FAILURE; | ||
648 | if (!edje_init()) | ||
649 | goto shutdown_ecore_evas; | ||
650 | edje_frametime_set(1.0/60.0); | ||
651 | |||
652 | args = ecore_getopt_parse(&optdesc, values, argc, argv); | ||
653 | if (args < 0) | ||
654 | { | ||
655 | fputs("Could not parse arguments.\n", stderr); | ||
656 | goto shutdown_edje; | ||
657 | } | ||
658 | else if (quit_option) | ||
659 | { | ||
660 | goto end; | ||
661 | } | ||
662 | else if (args >= argc) | ||
663 | { | ||
664 | fputs("Missing edje file to load.\n", stderr); | ||
665 | goto shutdown_edje; | ||
666 | } | ||
667 | |||
668 | ecore_app_args_set(argc, (const char **)argv); | ||
669 | edje_scale_set(opts.scale); | ||
670 | |||
671 | // check if the given edj file is there | ||
672 | if (access(argv[args], R_OK) == -1) | ||
673 | { | ||
674 | int e = errno; | ||
675 | fprintf(stderr, "ERROR: file '%s' not accessible, error %d (%s).\n", | ||
676 | argv[args], e, strerror(e)); | ||
677 | goto end; | ||
678 | } | ||
679 | |||
680 | opts.file = argv[args]; | ||
681 | if (opts.list_groups) | ||
682 | { | ||
683 | Eina_List *groups, *n; | ||
684 | const char *group; | ||
685 | groups = edje_file_collection_list(opts.file); | ||
686 | printf("%d groups in file '%s':\n", eina_list_count(groups), opts.file); | ||
687 | EINA_LIST_FOREACH(groups, n, group) | ||
688 | printf("\t'%s'\n", group); | ||
689 | edje_file_collection_list_free(groups); | ||
690 | goto end; | ||
691 | } | ||
692 | |||
693 | win = ecore_evas_new(opts.engine, 0, 0, opts.size.w, opts.size.h, NULL); | ||
694 | if (!win) | ||
695 | { | ||
696 | fprintf(stderr, | ||
697 | "ERROR: could not create window of " | ||
698 | "size %dx%d using engine %s.\n", | ||
699 | opts.size.w, opts.size.h, opts.engine ? opts.engine : "(auto)"); | ||
700 | goto shutdown_edje; | ||
701 | } | ||
702 | |||
703 | ecore_evas_callback_delete_request_set(win, _cb_delete); | ||
704 | evas = ecore_evas_get(win); | ||
705 | stack = _create_stack(evas, &opts); | ||
706 | if (!stack) | ||
707 | { | ||
708 | goto free_ecore_evas; | ||
709 | } | ||
710 | |||
711 | ecore_evas_object_associate(win, stack, ECORE_EVAS_OBJECT_ASSOCIATE_BASE); | ||
712 | |||
713 | if (opts.alpha) | ||
714 | ecore_evas_alpha_set(win, EINA_TRUE); | ||
715 | else if (opts.shaped) | ||
716 | ecore_evas_shaped_set(win, EINA_TRUE); | ||
717 | else | ||
718 | { | ||
719 | Evas_Object *bg = _create_bg(evas, &opts); | ||
720 | if (bg) evas_object_box_append(stack, bg); | ||
721 | } | ||
722 | |||
723 | edje = _create_edje(evas, &opts); | ||
724 | if (edje) | ||
725 | evas_object_box_append(stack, edje); | ||
726 | else | ||
727 | { | ||
728 | goto free_ecore_evas; | ||
729 | } | ||
730 | |||
731 | evas_object_focus_set(stack, EINA_TRUE); | ||
732 | evas_object_event_callback_add(stack, EVAS_CALLBACK_KEY_DOWN, | ||
733 | _key_down, &opts); | ||
734 | evas_object_event_callback_add(stack, EVAS_CALLBACK_CHANGED_SIZE_HINTS, | ||
735 | _reset_size_hints, edje); | ||
736 | |||
737 | if (opts.print) | ||
738 | { | ||
739 | edje_object_signal_callback_add(edje, "*", "*", _print_signal, NULL); | ||
740 | edje_object_message_handler_set(edje, _print_message, NULL); | ||
741 | } | ||
742 | |||
743 | if (opts.slave_mode) | ||
744 | { | ||
745 | #ifndef _WIN32 | ||
746 | int flags; | ||
747 | flags = fcntl(STDIN_FILENO, F_GETFL, 0); | ||
748 | flags |= O_NONBLOCK; | ||
749 | if (fcntl(STDIN_FILENO, F_SETFL, flags) < 0) | ||
750 | { | ||
751 | fprintf(stderr, "ERROR: Could not set stdin to non-block: %s\n", | ||
752 | strerror(errno)); | ||
753 | goto free_ecore_evas; | ||
754 | } | ||
755 | ecore_main_fd_handler_add(STDIN_FILENO, ECORE_FD_READ | ECORE_FD_ERROR, | ||
756 | _slave_mode, edje, NULL, NULL); | ||
757 | #else | ||
758 | /* TODO: port the code above to Windows */ | ||
759 | fprintf (stderr, "ERROR: slave mode not working on Windows\n"); | ||
760 | goto free_ecore_evas; | ||
761 | #endif | ||
762 | } | ||
763 | |||
764 | ecore_evas_borderless_set(win, opts.borderless); | ||
765 | ecore_evas_sticky_set(win, opts.sticky); | ||
766 | if (opts.title) | ||
767 | ecore_evas_title_set(win, opts.title); | ||
768 | |||
769 | if (opts.size.w <= 0) opts.size.w = 320; | ||
770 | if (opts.size.h <= 0) opts.size.h = 240; | ||
771 | ecore_evas_resize(win, opts.size.w, opts.size.h); | ||
772 | ecore_evas_show(win); | ||
773 | ecore_main_loop_begin(); | ||
774 | |||
775 | ecore_evas_free(win); | ||
776 | end: | ||
777 | edje_shutdown(); | ||
778 | ecore_evas_shutdown(); | ||
779 | |||
780 | return 0; | ||
781 | |||
782 | free_ecore_evas: | ||
783 | ecore_evas_free(win); | ||
784 | shutdown_edje: | ||
785 | edje_shutdown(); | ||
786 | shutdown_ecore_evas: | ||
787 | ecore_evas_shutdown(); | ||
788 | return EXIT_FAILURE; | ||
789 | } | ||