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 { "alarm calm", PUI_ANI_CMD_START, 1 },
40 { "bixby listening", PUI_ANI_CMD_START, -1 },
41 { "bixby speaking", PUI_ANI_CMD_START, -1 },
42 { "bixby_error", PUI_ANI_CMD_START, 1 },
43 { "blinking", 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 debug_info("Animation(%s) will be stopped !\n", pui_ani_get_id(app->ani_h));
54 /* stop animation running already */
55 e = pui_ani_control(app->ani_h, PUI_ANI_CMD_STOP, 0);
57 if (PUI_ERROR_NONE != e)
59 debug_error("Failed on stopping an animation !(cmd:%d, repeat:%d)\n", PUI_ANI_CMD_STOP, 0);
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");
88 /* stop animation running already */
90 pui_ani_destroy(app->ani_h);
94 ani_h = pui_ani_create(app->ph, ani_collection[ani_idx].id);
98 debug_error("Failed to create new PUI animation handle !\n");
100 if (++ani_idx >= n_animation)
108 debug_info("Animation(%s) will be started !\n", pui_ani_get_id(app->ani_h));
111 e = pui_ani_control(app->ani_h, PUI_ANI_CMD_START, ani_collection[ani_idx].repeat);
113 if (PUI_ERROR_NONE != e)
115 debug_error("Failed on playing an animation ! (cmd:%d, repeat:%d)\n", PUI_ANI_CMD_START, ani_collection[ani_idx].repeat);
119 if (++ani_idx >= n_animation)
126 _cb_key_up(void *data EINA_UNUSED, int type EINA_UNUSED, void *event)
128 app_data_t *app = (app_data_t *)data;
129 Ecore_Event_Key *ev = event;
131 debug_info("KEY: name:%s, sym:%s, code:%d\n", ev->keyname, ev->key, ev->keycode);
133 ani_collection_play(app);
135 return ECORE_CALLBACK_PASS_ON;
139 _cb_focus_in(void *data, int type EINA_UNUSED, void *event)
141 app_data_t *app = (app_data_t *)data;
142 Ecore_Wl2_Event_Focus_In *ev = (Ecore_Wl2_Event_Focus_In *)event;
150 return ECORE_CALLBACK_PASS_ON;
154 _cb_focus_out(void *data, int type EINA_UNUSED, void *event)
156 app_data_t *app = (app_data_t *)data;
157 Ecore_Wl2_Event_Focus_Out *ev = (Ecore_Wl2_Event_Focus_Out *)event;
165 return ECORE_CALLBACK_PASS_ON;
169 _cb_visibility_change(void *data, int type EINA_UNUSED, void *event)
171 app_data_t *app = (app_data_t *)data;
172 Ecore_Wl2_Event_Window_Visibility_Change *ev;
176 debug_info("Visibility change (window=0x%x, fully_obscured=%d)\n", ev->win, ev->fully_obscured);
178 if (ev->fully_obscured)
180 debug_info("Loose LED control !\n");
185 debug_info("Gain LED control !\n");
186 ani_collection_play(app);
189 return ECORE_CALLBACK_PASS_ON;
193 event_handlers_init(app_data_t *app)
195 Ecore_Event_Handler *h = NULL;
196 _ecore_event_hdls = eina_array_new(NUM_ECORE_EVENT_HANDLERS);
198 h = ecore_event_handler_add(ECORE_EVENT_KEY_UP, _cb_key_up, app);
199 eina_array_push(_ecore_event_hdls, h);
201 h = ecore_event_handler_add(ECORE_WL2_EVENT_FOCUS_IN, _cb_focus_in, app);
202 eina_array_push(_ecore_event_hdls, h);
204 h = ecore_event_handler_add(ECORE_WL2_EVENT_FOCUS_OUT, _cb_focus_out, app);
205 eina_array_push(_ecore_event_hdls, h);
207 h = ecore_event_handler_add(ECORE_WL2_EVENT_WINDOW_VISIBILITY_CHANGE, _cb_visibility_change, app);
208 eina_array_push(_ecore_event_hdls, h);
213 app_data_t *app = NULL;
214 const char *socket_name = NULL;
216 if (!ecore_wl2_init())
218 fprintf(stderr, "Failed to init ecore wl2 !\n");
222 socket_name = getenv("WAYLAND_DISPLAY");
225 socket_name = "wayland-0";
227 app = (app_data_t *)calloc(1, sizeof(app_data_t));
231 debug_error("Failed to allocate app data !\n");
235 app->ewd = ecore_wl2_display_connect(socket_name);
239 debug_error("Failed to connect to display !\n");
243 app->win = ecore_wl2_window_new(app->ewd, NULL, 0, 0, 1, 1);
247 debug_error("Failed to create a window !\n");
251 ecore_wl2_window_alpha_set(app->win, EINA_FALSE);
252 ecore_wl2_window_show(app->win);
253 ecore_wl2_window_commit(app->win, EINA_TRUE);
254 ecore_wl2_window_activate(app->win);
258 debug_error("Failed to init pui !\n");
262 app->ph = pui_create(app->win);
266 debug_error("Failed to create PUI handle !\n");
270 event_handlers_init(app);
272 ecore_main_loop_begin();
275 pui_ani_destroy(app->ani_h);
277 pui_destroy(app->ph);
280 ecore_wl2_shutdown();