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 { "alarm calm", PUI_ANI_CMD_START, 1 },
65 { "bixby listening", PUI_ANI_CMD_START, -1 },
66 { "bixby speaking", PUI_ANI_CMD_START, -1 },
67 { "bixby_error", PUI_ANI_CMD_START, 1 },
68 { "blinking", PUI_ANI_CMD_START, -1 },
69 { "notification", PUI_ANI_CMD_START, -1 },
73 ani_stop(app_data_t *app)
75 pui_error e = PUI_ERROR_NONE;
77 debug_info("Animation(%s) will be stopped !\n", pui_ani_get_id(app->ani_h));
79 /* stop animation running already */
80 e = pui_ani_control(app->ani_h, PUI_ANI_CMD_STOP, 0);
82 if (PUI_ERROR_NONE != e)
84 debug_error("Failed on stopping an animation !(cmd:%d, repeat:%d)\n", PUI_ANI_CMD_STOP, 0);
90 ani_collection_play(app_data_t *app)
92 static int ani_idx = 0;
94 pui_ani_h ani_h = NULL;
95 pui_error e = PUI_ERROR_NONE;
97 n_animation = sizeof(ani_collection) / sizeof(animation_t);
101 debug_error("No animation is available ! (n_animation=%d)\n", n_animation);
107 debug_error("Invalid pui_h handle !\n");
113 /* stop animation running already */
115 pui_ani_destroy(app->ani_h);
119 ani_h = pui_ani_create(app->ph, ani_collection[ani_idx].id);
123 debug_error("Failed to create new PUI animation handle !\n");
125 if (++ani_idx >= n_animation)
133 debug_info("Animation(%s) will be started !\n", pui_ani_get_id(app->ani_h));
136 e = pui_ani_control(app->ani_h, PUI_ANI_CMD_START, ani_collection[ani_idx].repeat);
138 if (PUI_ERROR_NONE != e)
140 debug_error("Failed on playing an animation ! (cmd:%d, repeat:%d)\n", PUI_ANI_CMD_START, ani_collection[ani_idx].repeat);
144 if (++ani_idx >= n_animation)
151 _cb_key_up(void *data EINA_UNUSED, int type EINA_UNUSED, void *event)
153 app_data_t *app = (app_data_t *)data;
154 Ecore_Event_Key *ev = event;
156 debug_info("KEY: name:%s, sym:%s, code:%d\n", ev->keyname, ev->key, ev->keycode);
158 ani_collection_play(app);
160 return ECORE_CALLBACK_PASS_ON;
164 _cb_focus_in(void *data, int type EINA_UNUSED, void *event)
166 app_data_t *app = (app_data_t *)data;
167 Ecore_Wl2_Event_Focus_In *ev = (Ecore_Wl2_Event_Focus_In *)event;
175 return ECORE_CALLBACK_PASS_ON;
179 _cb_focus_out(void *data, int type EINA_UNUSED, void *event)
181 app_data_t *app = (app_data_t *)data;
182 Ecore_Wl2_Event_Focus_Out *ev = (Ecore_Wl2_Event_Focus_Out *)event;
190 return ECORE_CALLBACK_PASS_ON;
194 _cb_visibility_change(void *data, int type EINA_UNUSED, void *event)
196 app_data_t *app = (app_data_t *)data;
197 Ecore_Wl2_Event_Window_Visibility_Change *ev;
201 debug_info("Visibility change (window=0x%x, fully_obscured=%d)\n", ev->win, ev->fully_obscured);
203 if (ev->fully_obscured)
205 debug_info("Loose LED control !\n");
210 debug_info("Gain LED control !\n");
211 ani_collection_play(app);
214 return ECORE_CALLBACK_PASS_ON;
218 event_handlers_init(app_data_t *app)
220 Ecore_Event_Handler *h = NULL;
221 _ecore_event_hdls = eina_array_new(NUM_ECORE_EVENT_HANDLERS);
223 h = ecore_event_handler_add(ECORE_EVENT_KEY_UP, _cb_key_up, app);
224 eina_array_push(_ecore_event_hdls, h);
226 h = ecore_event_handler_add(ECORE_WL2_EVENT_FOCUS_IN, _cb_focus_in, app);
227 eina_array_push(_ecore_event_hdls, h);
229 h = ecore_event_handler_add(ECORE_WL2_EVENT_FOCUS_OUT, _cb_focus_out, app);
230 eina_array_push(_ecore_event_hdls, h);
232 h = ecore_event_handler_add(ECORE_WL2_EVENT_WINDOW_VISIBILITY_CHANGE, _cb_visibility_change, app);
233 eina_array_push(_ecore_event_hdls, h);
238 app_data_t *app = NULL;
239 const char *socket_name = NULL;
241 if (!ecore_wl2_init())
243 fprintf(stderr, "Failed to init ecore wl2 !\n");
247 socket_name = getenv("WAYLAND_DISPLAY");
250 socket_name = "wayland-0";
252 app = (app_data_t *)calloc(1, sizeof(app_data_t));
256 debug_error("Failed to allocate app data !\n");
260 app->ewd = ecore_wl2_display_connect(socket_name);
264 debug_error("Failed to connect to display !\n");
268 app->win = ecore_wl2_window_new(app->ewd, NULL, 0, 0, 1, 1);
272 debug_error("Failed to create a window !\n");
276 ecore_wl2_window_alpha_set(app->win, EINA_FALSE);
277 ecore_wl2_window_show(app->win);
278 ecore_wl2_window_commit(app->win, EINA_TRUE);
279 ecore_wl2_window_activate(app->win);
283 debug_error("Failed to init pui !\n");
287 app->ph = pui_create(app->win);
291 debug_error("Failed to create PUI handle !\n");
295 event_handlers_init(app);
297 ecore_main_loop_begin();
300 pui_ani_destroy(app->ani_h);
302 pui_destroy(app->ph);
305 ecore_wl2_shutdown();