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
34 #include <Ecore_Wl2.h>
35 #include <Ecore_Input.h>
40 #define debug_error(msg, ...) \
42 fprintf(stderr, "[PUI sample][ERROR][PID:%d][%s] " msg, gpid, __FUNCTION__, ##__VA_ARGS__); \
45 #define debug_info(msg, ...) \
47 fprintf(stdout, "[PUI sample][INFO][PID:%d][%s] " msg, gpid, __FUNCTION__, ##__VA_ARGS__); \
50 typedef struct _animation animation_t;
58 typedef struct app_data app_data_t;
65 Ecore_Wl2_Display *ewd;
66 Ecore_Wl2_Window *win;
69 static Eina_Array *_ecore_event_hdls = NULL;
70 static animation_t ani_collection[] = {
71 { "system/easy_setup", PUI_ANI_CMD_START, -1 },
72 { "system/processing", PUI_ANI_CMD_START, -1 },
73 { "system/sw_update_done", PUI_ANI_CMD_START, -1 },
74 { "system/mic_off", PUI_ANI_CMD_START, -1 },
75 { "voice/listening", PUI_ANI_CMD_START, -1 },
76 { "voice/streaming", PUI_ANI_CMD_START, -1 },
77 { "voice/processing", PUI_ANI_CMD_START, -1 },
78 { "voice/speaking", PUI_ANI_CMD_START, -1 },
79 { "voice/timeout", PUI_ANI_CMD_START, -1 },
80 { "notification/normal", PUI_ANI_CMD_START, -1 },
81 { "notification/emergency", PUI_ANI_CMD_START, -1 },
82 { "notification/network_error", PUI_ANI_CMD_START, -1 },
83 { "notification/error", PUI_ANI_CMD_START, -1 },
84 { "notification/alarm", PUI_ANI_CMD_START, -1 },
85 { "bt/pairing", PUI_ANI_CMD_START, -1 },
86 { "bt/connected", PUI_ANI_CMD_START, -1 }
89 pui_ani_h ani_handles[sizeof(ani_collection) / sizeof(animation_t)];
92 ani_collection_play(app_data_t *app)
94 pui_error e = PUI_ERROR_NONE;
95 pui_ani_h ani_h = NULL;
99 debug_error("Invalid pui_h handle !\n");
103 while (!ani_handles[app->ani_idx])
107 if (++app->ani_idx >= app->n_animation)
111 debug_info("Animation(%s) will be started !\n", pui_ani_get_id(ani_handles[app->ani_idx]));
114 ani_h = ani_handles[app->ani_idx];
115 e = pui_ani_control(ani_h, PUI_ANI_CMD_START, ani_collection[app->ani_idx].repeat);
117 if (PUI_ERROR_NONE != e)
119 debug_error("Failed on playing an animation ! (cmd:%d, repeat:%d)\n", PUI_ANI_CMD_START, ani_collection[app->ani_idx].repeat);
123 if (++app->ani_idx >= app->n_animation)
130 _cb_key_up(void *data EINA_UNUSED, int type EINA_UNUSED, void *event)
132 app_data_t *app = (app_data_t *)data;
133 Ecore_Event_Key *ev = event;
135 debug_info("KEY: name:%s, sym:%s, code:%d\n", ev->keyname, ev->key, ev->keycode);
137 ani_collection_play(app);
139 return ECORE_CALLBACK_PASS_ON;
143 _cb_focus_in(void *data, int type EINA_UNUSED, void *event)
145 app_data_t *app = (app_data_t *)data;
146 Ecore_Wl2_Event_Focus_In *ev = (Ecore_Wl2_Event_Focus_In *)event;
154 return ECORE_CALLBACK_PASS_ON;
158 _cb_focus_out(void *data, int type EINA_UNUSED, void *event)
160 app_data_t *app = (app_data_t *)data;
161 Ecore_Wl2_Event_Focus_Out *ev = (Ecore_Wl2_Event_Focus_Out *)event;
169 return ECORE_CALLBACK_PASS_ON;
173 _cb_visibility_change(void *data, int type EINA_UNUSED, void *event)
175 app_data_t *app = (app_data_t *)data;
176 Ecore_Wl2_Event_Window_Visibility_Change *ev;
180 debug_info("Visibility change (window=0x%x, fully_obscured=%d)\n", ev->win, ev->fully_obscured);
182 return ECORE_CALLBACK_PASS_ON;
186 _cb_ani_started(void *data, int type EINA_UNUSED, void *event)
188 app_data_t *app = (app_data_t *)data;
189 PUI_Event_Animation_Status *ev;
193 debug_info("[%s] ani id=%s, status=%d, window=0x%x\n", __FUNCTION__, pui_ani_get_id(ev->ani_h), ev->status, ev->win);
195 return ECORE_CALLBACK_PASS_ON;
199 _cb_ani_stopped(void *data, int type EINA_UNUSED, void *event)
201 app_data_t *app = (app_data_t *)data;
202 PUI_Event_Animation_Status *ev;
206 debug_info("[%s] ani id=%s, status=%d, window=0x%x\n", __FUNCTION__, pui_ani_get_id(ev->ani_h), ev->status, ev->win);
208 /* decrease animation idx for starting from stopped animation */
211 return ECORE_CALLBACK_PASS_ON;
215 _cb_ani_ready_to_resume(void *data, int type EINA_UNUSED, void *event)
217 app_data_t *app = (app_data_t *)data;
218 PUI_Event_Animation_Status *ev;
222 debug_info("[%s] ani id=%s, status=%d, window=0x%x\n", __FUNCTION__, pui_ani_get_id(ev->ani_h), ev->status, ev->win);
224 /* resume animation */
226 ani_collection_play(app);
228 return ECORE_CALLBACK_PASS_ON;
232 event_handlers_init(app_data_t *app)
234 Ecore_Event_Handler *h = NULL;
235 _ecore_event_hdls = eina_array_new(NUM_ECORE_EVENT_HANDLERS);
237 h = ecore_event_handler_add(ECORE_EVENT_KEY_UP, _cb_key_up, app);
238 eina_array_push(_ecore_event_hdls, h);
240 h = ecore_event_handler_add(ECORE_WL2_EVENT_FOCUS_IN, _cb_focus_in, app);
241 eina_array_push(_ecore_event_hdls, h);
243 h = ecore_event_handler_add(ECORE_WL2_EVENT_FOCUS_OUT, _cb_focus_out, app);
244 eina_array_push(_ecore_event_hdls, h);
246 h = ecore_event_handler_add(ECORE_WL2_EVENT_WINDOW_VISIBILITY_CHANGE, _cb_visibility_change, app);
247 eina_array_push(_ecore_event_hdls, h);
249 h = ecore_event_handler_add(PUI_EVENT_ANI_STARTED, _cb_ani_started, app);
250 eina_array_push(_ecore_event_hdls, h);
252 h = ecore_event_handler_add(PUI_EVENT_ANI_STOPPED, _cb_ani_stopped, app);
253 eina_array_push(_ecore_event_hdls, h);
255 h = ecore_event_handler_add(PUI_EVENT_ANI_READY_TO_RESUME, _cb_ani_ready_to_resume, app);
256 eina_array_push(_ecore_event_hdls, h);
261 app_data_t *app = NULL;
262 const char *socket_name = NULL;
266 if (!ecore_wl2_init())
268 debug_error("Failed to init ecore wl2 !\n");
272 socket_name = getenv("WAYLAND_DISPLAY");
275 socket_name = "wayland-0";
277 app = (app_data_t *)calloc(1, sizeof(app_data_t));
281 debug_error("Failed to allocate app data !\n");
286 app->ewd = ecore_wl2_display_connect(socket_name);
290 debug_error("Failed to connect to display !\n");
294 app->win = ecore_wl2_window_new(app->ewd, NULL, 0, 0, 1, 1);
298 debug_error("Failed to create a window !\n");
302 ecore_wl2_window_alpha_set(app->win, EINA_FALSE);
303 ecore_wl2_window_show(app->win);
304 ecore_wl2_window_commit(app->win, EINA_TRUE);
305 ecore_wl2_window_activate(app->win);
309 debug_error("Failed to init pui !\n");
313 app->ph = pui_create(app->win);
317 debug_error("Failed to create PUI handle !\n");
321 app->n_animation = sizeof(ani_collection) / sizeof(animation_t);
323 for(int i=0;i<app->n_animation;i++)
325 ani_handles[i] = pui_ani_create(app->ph, ani_collection[i].id);
328 debug_error("Failed to create pui ani handle !(id:%s)\n", ani_collection[i].id);
331 event_handlers_init(app);
333 ecore_main_loop_begin();
335 if (app->n_animation > 0)
337 for(int i=0;i<app->n_animation;i++)
339 pui_ani_destroy(ani_handles[i]);
344 pui_destroy(app->ph);
347 ecore_wl2_shutdown();