2 #define NUM_ECORE_EVENT_HANDLERS 4
3 #define EFL_BETA_API_SUPPORT
6 #include <Ecore_Input.h>
9 #define debug_error(msg, ...) \
11 fprintf(stderr, "[ERROR][%s] " msg, __FUNCTION__, ##__VA_ARGS__); \
14 #define debug_info(msg, ...) \
16 fprintf(stdout, "[INFO][%s] " msg, __FUNCTION__, ##__VA_ARGS__); \
19 typedef struct _animation animation_t;
27 typedef struct app_data app_data_t;
33 Ecore_Wl2_Display *ewd;
34 Ecore_Wl2_Window *win;
37 static Eina_Array *_ecore_event_hdls = NULL;
38 static animation_t ani_collection[] = {
39 { "bixby_listening", PUI_ANI_CMD_START, 1 },
40 { "bixby_processing", PUI_ANI_CMD_START, -1 },
41 { "bixby_speaking", PUI_ANI_CMD_START, -1 },
42 { "bixby_error", PUI_ANI_CMD_START, 1 },
43 { "alarm", PUI_ANI_CMD_START, -1 },
44 { "notification", PUI_ANI_CMD_START, -1 },
48 ani_stop(app_data_t *app)
50 pui_error e = PUI_ERROR_NONE;
52 /* stop animation running already */
53 e = pui_ani_control(app->ani_h, PUI_ANI_CMD_STOP, 0);
55 if (PUI_ERROR_NONE != e)
57 debug_error("Failed on stopping an animation !(cmd:%d, repeat:%d)\n", PUI_ANI_CMD_STOP, 0);
61 debug_info("Animation(%s) will be stopped !\n", pui_ani_get_id(app->ani_h));
65 ani_collection_play(app_data_t *app)
67 static int ani_idx = 0;
69 pui_ani_h ani_h = NULL;
70 pui_error e = PUI_ERROR_NONE;
72 n_animation = sizeof(ani_collection) / sizeof(animation_t);
76 debug_error("No animation is available ! (n_animation=%d)\n", n_animation);
82 debug_error("Invalid pui_h handle !\n");
86 ani_h = pui_ani_create(app->ph, ani_collection[ani_idx].id);
90 debug_error("Failed to create new PUI animation handle !\n");
96 /* stop animation running already */
97 e = pui_ani_control(app->ani_h, PUI_ANI_CMD_STOP, 0);
99 if (PUI_ERROR_NONE != e)
101 debug_error("Failed on stopping an animation !(cmd:%d, repeat:%d)\n", PUI_ANI_CMD_STOP, 0);
105 debug_info("Animation(%s) will be stopped !\n", pui_ani_get_id(ani_h));
113 e = pui_ani_control(app->ani_h, PUI_ANI_CMD_START, ani_collection[ani_idx].repeat);
115 if (PUI_ERROR_NONE != e)
117 debug_error("Failed on playing an animation ! (cmd:%d, repeat:%d)\n", PUI_ANI_CMD_START, ani_collection[ani_idx].repeat);
121 debug_info("Animation(%s) will be started !\n", pui_ani_get_id(app->ani_h));
123 if (++ani_idx >= 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 if (ev->fully_obscured)
184 debug_info("Loose LED control !\n");
189 debug_info("Gain LED control !\n");
190 ani_collection_play(app);
193 return ECORE_CALLBACK_PASS_ON;
197 event_handlers_init(app_data_t *app)
199 Ecore_Event_Handler *h = NULL;
200 _ecore_event_hdls = eina_array_new(NUM_ECORE_EVENT_HANDLERS);
202 h = ecore_event_handler_add(ECORE_EVENT_KEY_UP, _cb_key_up, app);
203 eina_array_push(_ecore_event_hdls, h);
205 h = ecore_event_handler_add(ECORE_WL2_EVENT_FOCUS_IN, _cb_focus_in, app);
206 eina_array_push(_ecore_event_hdls, h);
208 h = ecore_event_handler_add(ECORE_WL2_EVENT_FOCUS_OUT, _cb_focus_out, app);
209 eina_array_push(_ecore_event_hdls, h);
211 h = ecore_event_handler_add(ECORE_WL2_EVENT_WINDOW_VISIBILITY_CHANGE, _cb_visibility_change, app);
212 eina_array_push(_ecore_event_hdls, h);
217 app_data_t *app = NULL;
218 const char *socket_name = NULL;
220 if (!ecore_wl2_init())
222 fprintf(stderr, "Failed to init ecore wl2 !\n");
226 socket_name = getenv("WAYLAND_DISPLAY");
229 socket_name = "wayland-0";
231 app = (app_data_t *)calloc(1, sizeof(app_data_t));
235 debug_error("Failed to allocate app data !\n");
239 app->ewd = ecore_wl2_display_connect(socket_name);
243 debug_error("Failed to connect to display !\n");
247 app->win = ecore_wl2_window_new(app->ewd, NULL, 0, 0, 1, 1);
251 debug_error("Failed to create a window !\n");
255 ecore_wl2_window_alpha_set(app->win, EINA_FALSE);
256 ecore_wl2_window_show(app->win);
257 ecore_wl2_window_commit(app->win, EINA_TRUE);
258 ecore_wl2_window_activate(app->win);
262 debug_error("Failed to init pui !\n");
266 app->ph = pui_create(app->win);
270 debug_error("Failed to create PUI handle !\n");
274 event_handlers_init(app);
276 ecore_main_loop_begin();
279 pui_ani_destroy(app->ani_h);
281 pui_destroy(app->ph);
284 ecore_wl2_shutdown();