4 #define NUM_ECORE_EVENT_HANDLERS 4
6 #define debug_error(msg, ...) \
8 fprintf(stderr, "[ERROR][%s] " msg, __FUNCTION__, ##__VA_ARGS__); \
11 #define debug_info(msg, ...) \
13 fprintf(stdout, "[INFO][%s] " msg, __FUNCTION__, ##__VA_ARGS__); \
16 typedef struct _animation animation_t;
24 typedef struct app_data app_data_t;
30 Ecore_Wl2_Display *ewd;
31 Ecore_Wl2_Window *win;
34 static Eina_Array *_ecore_event_hdls = NULL;
35 static animation_t ani_collection[] = {
36 { "bixby_listening", PUI_ANI_CMD_START, PUI_ANI_OPT_ONCE },
37 { "bixby_processing", PUI_ANI_CMD_START, PUI_ANI_OPT_REPEAT },
38 { "bixby_speaking", PUI_ANI_CMD_START, PUI_ANI_OPT_REPEAT },
39 { "bixby_error", PUI_ANI_CMD_START, PUI_ANI_OPT_ONCE },
40 { "alarm", PUI_ANI_CMD_START, PUI_ANI_OPT_REPEAT },
41 { "notification", PUI_ANI_CMD_START, PUI_ANI_OPT_REPEAT },
45 ani_play(app_data_t *app, pui_ani_opt opt)
49 if (!app || !app->ani_h)
51 debug_error("Invalid app data or pui animation handle !\n");
55 e = pui_ani_control(app->ani_h, PUI_ANI_CMD_START, opt);
57 if (PUI_ERROR_NONE != e)
59 debug_error("Failed on playing an animation ! (cmd:%d, opt:%d)\n", PUI_ANI_CMD_START, opt);
63 debug_info("Animation(%s) will be started !\n", pui_ani_get_id(ani_h));
67 ani_stop(app_data_t *app)
71 if (!app || !app->ani_h)
73 debug_error("Invalid app data or pui animation handle !\n");
77 e = pui_ani_control(app->ani_h, PUI_ANI_CMD_STOP, PUI_ANI_OPT_ONCE);
79 if (PUI_ERROR_NONE != e)
81 debug_error("Failed on stopping an animation !(cmd:%d, opt:%d)\n", PUI_ANI_CMD_STOP, PUI_ANI_OPT_ONCE);
85 debug_info("Animation(%s) will be stopped !\n", pui_ani_get_id(ani_h));
89 ani_collection_play(app_data_t *app)
91 static int ani_idx = 0;
93 pui_ani_h ani_h = NULL;
94 pui_error e = PUI_ERROR_NONE;
96 n_animation = ani_collection / sizeof(animation_t);
100 debug_error("No animation is available ! (n_animation=%d)\n", n_animation);
106 debug_error("Invalid pui_h handle !\n");
110 ani_h = pui_ani_create(app->ph, ani_collection[ani_idx].id);
114 debug_error("Failed to create new PUI animation handle !\n");
125 ani_play(app, ani_collection[ani_idx].opt);
127 if (++ani_idx >= n_animation)
135 pui_ani_control(ani_h, PUI_ANI_CMD_STOP, PUI_ANI_OPT_NONE);
136 pui_ani_destroy(ani_h);
141 _cb_key_up(void *data EINA_UNUSED, int type EINA_UNUSED, void *event)
143 app_data_t *app = (app_data_t *)data;
144 Ecore_Event_Key *ev = event;
146 debug_info("KEY: name:%s, sym:%s, code:%d\n", ev->keyname, ev->key, ev->keycode);
148 ani_collection_play(app);
150 return ECORE_CALLBACK_PASS_ON;
154 _cb_focus_in(void *data, int type EINA_UNUSED, void *event)
156 app_data_t *app = (app_data_t *)data;
157 Ecore_Wl2_Event_Focus_In *ev = (Ecore_Wl2_Event_Focus_In *)event;
165 return ECORE_CALLBACK_PASS_ON;
169 _cb_focus_out(void *data, int type EINA_UNUSED, void *event)
171 app_data_t *app = (app_data_t *)data;
172 Ecore_Wl2_Event_Focus_Out *ev = (Ecore_Wl2_Event_Focus_Out *)event;
180 return ECORE_CALLBACK_PASS_ON;
184 _cb_visibility_change(void *data, int type EINA_UNUSED, void *event)
186 app_data_t *app = (app_data_t *)data;
187 Ecore_Wl2_Event_Window_Visibility_Change *ev;
191 debug_info("Visibility change (window=0x%x, fully_obscured=%d)\n", ev->win, ev->fully_obscured);
193 if (ev->fully_obscured)
195 debug_info("Loose LED control !\n");
200 debug_info("Gain LED control !\n");
201 ani_collection_play(app);
204 return ECORE_CALLBACK_PASS_ON;
208 event_handlers_init(app_data_t *app)
210 Ecore_Event_Handler *h = NULL;
211 _ecore_event_hdls = eina_array_new(NUM_ECORE_EVENT_HANDLERS);
213 h = ecore_event_handler_add(ECORE_EVENT_KEY_UP, _cb_key_up, app);
214 eina_array_push(_ecore_event_hdls, h);
216 h = ecore_event_handler_add(ECORE_WL2_EVENT_FOCUS_IN, _cb_focus_in, app);
217 eina_array_push(_ecore_event_hdls, h);
219 h = ecore_event_handler_add(ECORE_WL2_EVENT_FOCUS_OUT, _cb_focus_out, app);
220 eina_array_push(_ecore_event_hdls, h);
222 h = ecore_event_handler_add(ECORE_WL2_EVENT_WINDOW_VISIBILITY_CHANGE, _cb_visibility_change, app);
223 eina_array_push(_ecore_event_hdls, h);
228 app_data_t *app = NULL;
229 const char *socket_name = NULL;
231 if (!ecore_wl2_init())
233 fprintf(stderr, "Failed to init ecore wl2 !\n");
237 socket_name = getenv("WAYLAND_DISPLAY");
240 socket_name = "wayland-0";
242 app = (app_data_t *)calloc(1, sizeof(app_data_t));
246 debug_error("Failed to allocate app data !\n");
250 app->ewd = ecore_wl2_display_connect(socket_name);
254 debug_error("Failed to connect to display !\n");
258 app->win = ecore_wl2_window_new(app->ewd, NULL, 0, 0, 1, 1);
262 debug_error("Failed to create a window !\n");
266 ecore_wl2_window_alpha_set(app->win, EINA_FALSE);
267 ecore_wl2_window_show(app->win);
268 ecore_wl2_window_commit(app->win, EINA_TRUE);
269 ecore_wl2_window_activate(app->win);
273 debug_error("Failed to init pui !\n");
277 app->ph = pui_create(app->win);
281 debug_error("Failed to create PUI handle !\n");
285 event_handlers_init(app);
287 ecore_main_loop_begin();
290 pui_ani_destroy(app->ani_h)
292 pui_destroy(app->ph);
295 ecore_wl2_shutdown();