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
27 #define NUM_ECORE_EVENT_HANDLERS 4
28 #define EFL_BETA_API_SUPPORT
30 #include <Ecore_Wl2.h>
31 #include <Ecore_Input.h>
34 #define debug_error(msg, ...) \
36 fprintf(stderr, "[ERROR][%s] " msg, __FUNCTION__, ##__VA_ARGS__); \
39 #define debug_info(msg, ...) \
41 fprintf(stdout, "[INFO][%s] " msg, __FUNCTION__, ##__VA_ARGS__); \
44 typedef struct _animation animation_t;
52 typedef struct app_data app_data_t;
58 Ecore_Wl2_Display *ewd;
59 Ecore_Wl2_Window *win;
62 static Eina_Array *_ecore_event_hdls = NULL;
63 static animation_t ani_collection[] = {
64 { "processing", PUI_ANI_CMD_START, -1 },
65 { "listening", PUI_ANI_CMD_START, -1 },
66 { "speaking", PUI_ANI_CMD_START, -1 },
67 { "streaming", PUI_ANI_CMD_START, -1 },
69 { "alarm calm", PUI_ANI_CMD_START, 1 },
70 { "bixby listening", PUI_ANI_CMD_START, -1 },
71 { "bixby speaking", PUI_ANI_CMD_START, -1 },
72 { "bixby_error", PUI_ANI_CMD_START, 1 },
73 { "blinking", PUI_ANI_CMD_START, -1 },
74 { "notification", PUI_ANI_CMD_START, -1 },
79 ani_stop(app_data_t *app)
81 pui_error e = PUI_ERROR_NONE;
83 debug_info("Animation(%s) will be stopped !\n", pui_ani_get_id(app->ani_h));
85 /* stop animation running already */
86 e = pui_ani_control(app->ani_h, PUI_ANI_CMD_STOP, 0);
88 if (PUI_ERROR_NONE != e)
90 debug_error("Failed on stopping an animation !(cmd:%d, repeat:%d)\n", PUI_ANI_CMD_STOP, 0);
96 ani_collection_play(app_data_t *app)
98 static int ani_idx = 0;
100 pui_ani_h ani_h = NULL;
101 pui_error e = PUI_ERROR_NONE;
103 n_animation = sizeof(ani_collection) / sizeof(animation_t);
107 debug_error("No animation is available ! (n_animation=%d)\n", n_animation);
113 debug_error("Invalid pui_h handle !\n");
119 /* stop animation running already */
121 pui_ani_destroy(app->ani_h);
125 ani_h = pui_ani_create(app->ph, ani_collection[ani_idx].id);
129 debug_error("Failed to create new PUI animation handle !\n");
131 if (++ani_idx >= n_animation)
139 debug_info("Animation(%s) will be started !\n", pui_ani_get_id(app->ani_h));
142 e = pui_ani_control(app->ani_h, PUI_ANI_CMD_START, ani_collection[ani_idx].repeat);
144 if (PUI_ERROR_NONE != e)
146 debug_error("Failed on playing an animation ! (cmd:%d, repeat:%d)\n", PUI_ANI_CMD_START, ani_collection[ani_idx].repeat);
150 if (++ani_idx >= n_animation)
157 _cb_key_up(void *data EINA_UNUSED, int type EINA_UNUSED, void *event)
159 app_data_t *app = (app_data_t *)data;
160 Ecore_Event_Key *ev = event;
162 debug_info("KEY: name:%s, sym:%s, code:%d\n", ev->keyname, ev->key, ev->keycode);
164 ani_collection_play(app);
166 return ECORE_CALLBACK_PASS_ON;
170 _cb_focus_in(void *data, int type EINA_UNUSED, void *event)
172 app_data_t *app = (app_data_t *)data;
173 Ecore_Wl2_Event_Focus_In *ev = (Ecore_Wl2_Event_Focus_In *)event;
181 return ECORE_CALLBACK_PASS_ON;
185 _cb_focus_out(void *data, int type EINA_UNUSED, void *event)
187 app_data_t *app = (app_data_t *)data;
188 Ecore_Wl2_Event_Focus_Out *ev = (Ecore_Wl2_Event_Focus_Out *)event;
196 return ECORE_CALLBACK_PASS_ON;
200 _cb_visibility_change(void *data, int type EINA_UNUSED, void *event)
202 app_data_t *app = (app_data_t *)data;
203 Ecore_Wl2_Event_Window_Visibility_Change *ev;
207 debug_info("Visibility change (window=0x%x, fully_obscured=%d)\n", ev->win, ev->fully_obscured);
209 if (ev->fully_obscured)
211 debug_info("Loose LED control !\n");
216 debug_info("Gain LED control !\n");
217 ani_collection_play(app);
220 return ECORE_CALLBACK_PASS_ON;
224 event_handlers_init(app_data_t *app)
226 Ecore_Event_Handler *h = NULL;
227 _ecore_event_hdls = eina_array_new(NUM_ECORE_EVENT_HANDLERS);
229 h = ecore_event_handler_add(ECORE_EVENT_KEY_UP, _cb_key_up, app);
230 eina_array_push(_ecore_event_hdls, h);
232 h = ecore_event_handler_add(ECORE_WL2_EVENT_FOCUS_IN, _cb_focus_in, app);
233 eina_array_push(_ecore_event_hdls, h);
235 h = ecore_event_handler_add(ECORE_WL2_EVENT_FOCUS_OUT, _cb_focus_out, app);
236 eina_array_push(_ecore_event_hdls, h);
238 h = ecore_event_handler_add(ECORE_WL2_EVENT_WINDOW_VISIBILITY_CHANGE, _cb_visibility_change, app);
239 eina_array_push(_ecore_event_hdls, h);
244 app_data_t *app = NULL;
245 const char *socket_name = NULL;
247 if (!ecore_wl2_init())
249 fprintf(stderr, "Failed to init ecore wl2 !\n");
253 socket_name = getenv("WAYLAND_DISPLAY");
256 socket_name = "wayland-0";
258 app = (app_data_t *)calloc(1, sizeof(app_data_t));
262 debug_error("Failed to allocate app data !\n");
266 app->ewd = ecore_wl2_display_connect(socket_name);
270 debug_error("Failed to connect to display !\n");
274 app->win = ecore_wl2_window_new(app->ewd, NULL, 0, 0, 1, 1);
278 debug_error("Failed to create a window !\n");
282 ecore_wl2_window_alpha_set(app->win, EINA_FALSE);
283 ecore_wl2_window_show(app->win);
284 ecore_wl2_window_commit(app->win, EINA_TRUE);
285 ecore_wl2_window_activate(app->win);
289 debug_error("Failed to init pui !\n");
293 app->ph = pui_create(app->win);
297 debug_error("Failed to create PUI handle !\n");
301 event_handlers_init(app);
303 ecore_main_loop_begin();
306 pui_ani_destroy(app->ani_h);
308 pui_destroy(app->ph);
311 ecore_wl2_shutdown();