2 * Copyright © 2019 Samsung Electronics co., Ltd. All Rights Reserved.
4 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sublicense, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial
14 * portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29 #define NUM_ECORE_EVENT_HANDLERS 7
31 /* pre-requisite to use ecore_wl2 APIs */
32 #define EFL_BETA_API_SUPPORT
36 #include <Ecore_Wl2.h>
37 #include <Ecore_Input.h>
42 #define debug_error(msg, ...) \
44 fprintf(stderr, "[PUI sample][ERROR][PID:%d][%s] " msg, gpid, __FUNCTION__, ##__VA_ARGS__); \
47 #define debug_info(msg, ...) \
49 fprintf(stdout, "[PUI sample][INFO][PID:%d][%s] " msg, gpid, __FUNCTION__, ##__VA_ARGS__); \
52 typedef struct _animation animation_t;
60 typedef struct app_data app_data_t;
68 Ecore_Wl2_Display *ewd;
69 Ecore_Wl2_Window *win;
72 static Eina_Array *_ecore_event_hdls = NULL;
73 static animation_t ani_collection[] = {
74 { "system/easy_setup", PUI_ANI_CMD_START, -1 },
75 { "system/processing", PUI_ANI_CMD_START, -1 },
76 { "system/sw_update_done", PUI_ANI_CMD_START, 1 },
77 { "system/mic_off", PUI_ANI_CMD_START, 1 },
78 { "voice/listening", PUI_ANI_CMD_START, 1 },
79 { "voice/streaming", PUI_ANI_CMD_START, -1 },
80 { "voice/processing", PUI_ANI_CMD_START, -1 },
81 { "voice/speaking", PUI_ANI_CMD_START, -1 },
82 { "voice/timeout", PUI_ANI_CMD_START, 1 },
83 { "notification/normal", PUI_ANI_CMD_START, 1 },
84 { "notification/emergency", PUI_ANI_CMD_START, -1 },
85 { "notification/network_error", PUI_ANI_CMD_START, -1 },
86 { "notification/error", PUI_ANI_CMD_START, -1 },
87 { "notification/alarm", PUI_ANI_CMD_START, 1 },
88 { "bt/pairing", PUI_ANI_CMD_START, -1 },
89 { "bt/connected", PUI_ANI_CMD_START, 3 }
92 pui_ani_h ani_handles[sizeof(ani_collection) / sizeof(animation_t)];
95 ani_collection_play(app_data_t *app)
97 pui_error e = PUI_ERROR_NONE;
98 pui_ani_h ani_h = NULL;
102 debug_error("Invalid pui_h handle !\n");
106 while (!ani_handles[app->ani_idx])
110 if (++app->ani_idx >= app->n_animation)
114 debug_info("Animation(%s) will be started !\n", pui_ani_get_id(ani_handles[app->ani_idx]));
117 ani_h = ani_handles[app->ani_idx];
118 e = pui_ani_control(ani_h, PUI_ANI_CMD_START, ani_collection[app->ani_idx].repeat);
120 if (PUI_ERROR_NONE != e)
122 debug_error("Failed on playing an animation ! (cmd:%d, repeat:%d)\n", PUI_ANI_CMD_START, ani_collection[app->ani_idx].repeat);
126 if (++app->ani_idx >= app->n_animation)
133 _cb_key_up(void *data EINA_UNUSED, int type EINA_UNUSED, void *event)
135 app_data_t *app = (app_data_t *)data;
136 Ecore_Event_Key *ev = event;
138 debug_info("KEY: name:%s, sym:%s, code:%d\n", ev->keyname, ev->key, ev->keycode);
140 ani_collection_play(app);
142 return ECORE_CALLBACK_PASS_ON;
146 _cb_focus_in(void *data, int type EINA_UNUSED, void *event)
148 app_data_t *app = (app_data_t *)data;
149 Ecore_Wl2_Event_Focus_In *ev = (Ecore_Wl2_Event_Focus_In *)event;
157 return ECORE_CALLBACK_PASS_ON;
161 _cb_focus_out(void *data, int type EINA_UNUSED, void *event)
163 app_data_t *app = (app_data_t *)data;
164 Ecore_Wl2_Event_Focus_Out *ev = (Ecore_Wl2_Event_Focus_Out *)event;
172 return ECORE_CALLBACK_PASS_ON;
176 _cb_visibility_change(void *data, int type EINA_UNUSED, void *event)
178 app_data_t *app = (app_data_t *)data;
179 Ecore_Wl2_Event_Window_Visibility_Change *ev;
183 debug_info("Visibility change (window=0x%x, fully_obscured=%d)\n", ev->win, ev->fully_obscured);
185 return ECORE_CALLBACK_PASS_ON;
189 _cb_ani_started(void *data, int type EINA_UNUSED, void *event)
191 app_data_t *app = (app_data_t *)data;
192 PUI_Event_Animation_Status *ev;
196 debug_info("[%s] ani id=%s, status=%d, window=0x%x\n", __FUNCTION__, pui_ani_get_id(ev->ani_h), ev->status, ev->win);
198 return ECORE_CALLBACK_PASS_ON;
202 _cb_ani_stopped(void *data, int type EINA_UNUSED, void *event)
204 app_data_t *app = (app_data_t *)data;
205 PUI_Event_Animation_Status *ev;
209 debug_info("[%s] ani id=%s, status=%d, window=0x%x\n", __FUNCTION__, pui_ani_get_id(ev->ani_h), ev->status, ev->win);
211 /* decrease animation idx for starting from stopped animation */
214 return ECORE_CALLBACK_PASS_ON;
218 _cb_ani_ready_to_resume(void *data, int type EINA_UNUSED, void *event)
220 app_data_t *app = (app_data_t *)data;
221 PUI_Event_Animation_Status *ev;
225 debug_info("[%s] ani id=%s, status=%d, window=0x%x\n", __FUNCTION__, pui_ani_get_id(ev->ani_h), ev->status, ev->win);
227 /* resume animation */
229 ani_collection_play(app);
231 return ECORE_CALLBACK_PASS_ON;
235 _ani_play(app_data_t *app, const char *ani_type, int repeat)
237 pui_error e = PUI_ERROR_NONE;
238 pui_ani_h ani_h = NULL;
243 debug_error("Invalid pui_h handle !\n");
247 for (int i = 0; i < app->n_animation; i++)
249 if (!strncmp(ani_collection[i].id, ani_type, strlen(ani_type)))
257 debug_error("%s is not supported animation id.\n", ani_type);
261 debug_info("Animation(%s) will be started !\n", pui_ani_get_id(ani_handles[idx]));
264 ani_h = ani_handles[idx];
265 e = pui_ani_control(ani_h, PUI_ANI_CMD_START, repeat);
267 if (PUI_ERROR_NONE != e)
269 debug_error("Failed on playing an animation ! (cmd:%d, repeat:%d)\n", PUI_ANI_CMD_START, repeat);
273 app->manual_idx = idx;
277 _ani_stop(app_data_t *app)
279 pui_error e = PUI_ERROR_NONE;
280 pui_ani_h ani_h = NULL;
285 debug_error("Invalid pui_h handle !\n");
289 if (app->manual_idx < 0)
291 debug_info("manual animation is not started\n");
295 debug_info("Animation(%s) will be stop !\n", pui_ani_get_id(ani_handles[app->manual_idx]));
298 ani_h = ani_handles[app->manual_idx];
299 e = pui_ani_control(ani_h, PUI_ANI_CMD_STOP, -1);
301 if (PUI_ERROR_NONE != e)
303 debug_error("Failed on stop an animation ! (cmd:%d)\n", PUI_ANI_CMD_STOP);
306 app->manual_idx = -1;
313 printf(" Supported commands: help (Print this help text)\n");
314 printf(" : q/quit (Quit program)\n");
315 printf(" : play {ani_id} {repeat} (play manual animation)\n");
316 printf(" ex> play system/processing 2\n");
317 printf(" : stop (stop manual animation)\n");
322 _process_options(app_data_t *app, char *options)
326 char ani_type[MAX_STR] = {0, };
329 tmp = strtok_r(options, " ", &buf_ptr);
332 if (!strncmp(options, "q", MAX_STR) || !strncmp(options, "quit", MAX_STR)) {
333 ecore_main_loop_quit();
335 else if (!strncmp(options, "help", MAX_STR)) {
338 else if (!strncmp(tmp, "play", sizeof("play"))) {
340 tmp = strtok_r(NULL, " ", &buf_ptr);
344 strncpy(ani_type, tmp, MAX_STR - 1);
355 if (strlen(ani_type) <= 0) {
356 printf("Please input valid arguments for ani type\n");
360 _ani_play(app, ani_type, repeat);
362 else if (!strncmp(tmp, "stop", sizeof("stop"))) {
366 printf("Invalid arguments\n");
372 _stdin_cb(void *data, Ecore_Fd_Handler *handler EINA_UNUSED)
374 app_data_t *app = (app_data_t *)data;
375 char c, buf[MAX_STR] = {0, };
378 while ((c = getchar()) != EOF) {
379 if (c == '\n') break;
380 if (count >= MAX_STR) break;
386 _process_options(app, buf);
388 return ECORE_CALLBACK_RENEW;
393 event_handlers_init(app_data_t *app)
395 Ecore_Event_Handler *h = NULL;
396 _ecore_event_hdls = eina_array_new(NUM_ECORE_EVENT_HANDLERS);
398 h = ecore_event_handler_add(ECORE_EVENT_KEY_UP, _cb_key_up, app);
399 eina_array_push(_ecore_event_hdls, h);
401 h = ecore_event_handler_add(ECORE_WL2_EVENT_FOCUS_IN, _cb_focus_in, app);
402 eina_array_push(_ecore_event_hdls, h);
404 h = ecore_event_handler_add(ECORE_WL2_EVENT_FOCUS_OUT, _cb_focus_out, app);
405 eina_array_push(_ecore_event_hdls, h);
407 h = ecore_event_handler_add(ECORE_WL2_EVENT_WINDOW_VISIBILITY_CHANGE, _cb_visibility_change, app);
408 eina_array_push(_ecore_event_hdls, h);
410 h = ecore_event_handler_add(PUI_EVENT_ANI_STARTED, _cb_ani_started, app);
411 eina_array_push(_ecore_event_hdls, h);
413 h = ecore_event_handler_add(PUI_EVENT_ANI_STOPPED, _cb_ani_stopped, app);
414 eina_array_push(_ecore_event_hdls, h);
416 h = ecore_event_handler_add(PUI_EVENT_ANI_READY_TO_RESUME, _cb_ani_ready_to_resume, app);
417 eina_array_push(_ecore_event_hdls, h);
420 int main(int argc, char **argv)
422 app_data_t *app = NULL;
423 const char *socket_name = NULL;
427 if (!ecore_wl2_init())
429 debug_error("Failed to init ecore wl2 !\n");
433 socket_name = getenv("WAYLAND_DISPLAY");
436 socket_name = "wayland-0";
438 app = (app_data_t *)calloc(1, sizeof(app_data_t));
442 debug_error("Failed to allocate app data !\n");
447 app->manual_idx = -1;
448 app->ewd = ecore_wl2_display_connect(socket_name);
452 debug_error("Failed to connect to display !\n");
456 app->win = ecore_wl2_window_new(app->ewd, NULL, 0, 0, 1, 1);
460 debug_error("Failed to create a window !\n");
464 ecore_wl2_window_alpha_set(app->win, EINA_FALSE);
465 ecore_wl2_window_show(app->win);
466 ecore_wl2_window_commit(app->win, EINA_TRUE);
467 ecore_wl2_window_activate(app->win);
471 debug_error("Failed to init pui !\n");
475 app->ph = pui_create(app->win);
479 debug_error("Failed to create PUI handle !\n");
483 app->n_animation = sizeof(ani_collection) / sizeof(animation_t);
485 for(int i=0;i<app->n_animation;i++)
487 ani_handles[i] = pui_ani_create(app->ph, ani_collection[i].id);
490 debug_error("Failed to create pui ani handle !(id:%s)\n", ani_collection[i].id);
493 event_handlers_init(app);
494 if (argc >= 2 && !strncmp(argv[1], "stdin", sizeof("stdin")))
496 ecore_main_fd_handler_add(STDIN_FILENO, ECORE_FD_READ, _stdin_cb, app, NULL, NULL);
499 ecore_main_loop_begin();
501 if (app->n_animation > 0)
503 for(int i=0;i<app->n_animation;i++)
505 pui_ani_destroy(ani_handles[i]);
510 pui_destroy(app->ph);
513 ecore_wl2_shutdown();