2 * Ecore example illustrating the ews of ecore evas usage.
4 * You'll need at least one Evas engine built for it (excluding the
5 * buffer one). See stdout/stderr for output.
8 * gcc -o ecore_evas_ews_example ecore_evas_ews_example.c `pkg-config --libs --cflags ecore-evas`
13 #include <Ecore_Evas.h>
19 _wm_win_add(void *data, int type, void *event_info)
21 Ecore_Evas *ee = event_info;
22 printf("WM: new window=%p\n", ee);
27 _wm_win_move(void *data, int type, void *event_info)
29 Ecore_Evas *ee = event_info;
31 ecore_evas_geometry_get(ee, &x, &y, NULL, NULL);
32 printf("WM: window=%p moved to %d,%d\n", ee, x, y);
37 _wm_win_resize(void *data, int type, void *event_info)
39 Ecore_Evas *ee = event_info;
41 ecore_evas_geometry_get(ee, NULL, NULL, &w, &h);
42 printf("WM: window=%p resized to %dx%d\n", ee, w, h);
47 _wm_win_show(void *data, int type, void *event_info)
49 Ecore_Evas *ee = event_info;
50 printf("WM: show window=%p\n", ee);
55 optional_ews_window_manager_setup(void)
57 ecore_event_handler_add(ECORE_EVAS_EWS_EVENT_ADD, _wm_win_add, NULL);
58 ecore_event_handler_add(ECORE_EVAS_EWS_EVENT_MOVE, _wm_win_move, NULL);
59 ecore_event_handler_add(ECORE_EVAS_EWS_EVENT_RESIZE, _wm_win_resize, NULL);
60 ecore_event_handler_add(ECORE_EVAS_EWS_EVENT_SHOW, _wm_win_show, NULL);
62 /* one may use any known unique identifier, like an app function pointer */
63 ecore_evas_ews_manager_set(optional_ews_window_manager_setup);
67 optional_ews_setup(void)
72 ecore_evas_ews_setup(0, 0, 800, 600); /* "screen" size */
73 e = ecore_evas_ews_evas_get(); /* forces "screen" to be allocated */
75 bg = evas_object_rectangle_add(e);
76 evas_object_color_set(bg, 128, 32, 32, 255);
77 ecore_evas_ews_background_set(bg);
81 _stdin_cb(void *data, Ecore_Fd_Handler *handler)
89 ecore_main_loop_quit();
95 printf("hide all windows\n");
96 EINA_LIST_FOREACH(ecore_evas_ews_children_get(), l, ee)
100 printf("show all windows\n");
101 EINA_LIST_FOREACH(ecore_evas_ews_children_get(), l, ee)
105 printf("move all windows left\n");
106 EINA_LIST_FOREACH(ecore_evas_ews_children_get(), l, ee)
109 ecore_evas_geometry_get(ee, &x, &y, NULL, NULL);
110 ecore_evas_move(ee, x - 10, y);
114 printf("move all windows right\n");
115 EINA_LIST_FOREACH(ecore_evas_ews_children_get(), l, ee)
118 ecore_evas_geometry_get(ee, &x, &y, NULL, NULL);
119 ecore_evas_move(ee, x + 10, y);
123 printf("move all windows top\n");
124 EINA_LIST_FOREACH(ecore_evas_ews_children_get(), l, ee)
127 ecore_evas_geometry_get(ee, &x, &y, NULL, NULL);
128 ecore_evas_move(ee, x, y - 10);
132 printf("move all windows bottom\n");
133 EINA_LIST_FOREACH(ecore_evas_ews_children_get(), l, ee)
136 ecore_evas_geometry_get(ee, &x, &y, NULL, NULL);
137 ecore_evas_move(ee, x, y + 10);
141 printf("make all windows smaller\n");
142 EINA_LIST_FOREACH(ecore_evas_ews_children_get(), l, ee)
145 ecore_evas_geometry_get(ee, NULL, NULL, &w, &h);
146 ecore_evas_resize(ee, w - 10, h - 10);
150 printf("make all windows bigger\n");
151 EINA_LIST_FOREACH(ecore_evas_ews_children_get(), l, ee)
154 ecore_evas_geometry_get(ee, NULL, NULL, &w, &h);
155 ecore_evas_resize(ee, w + 10, h + 10);
159 printf("make all windows unmaximized\n");
160 EINA_LIST_FOREACH(ecore_evas_ews_children_get(), l, ee)
161 ecore_evas_maximized_set(ee, EINA_FALSE);
164 printf("make all windows maximized\n");
165 EINA_LIST_FOREACH(ecore_evas_ews_children_get(), l, ee)
166 ecore_evas_maximized_set(ee, EINA_TRUE);
169 printf("make all windows uniconified\n");
170 EINA_LIST_FOREACH(ecore_evas_ews_children_get(), l, ee)
171 ecore_evas_iconified_set(ee, EINA_FALSE);
174 printf("make all windows iconified\n");
175 EINA_LIST_FOREACH(ecore_evas_ews_children_get(), l, ee)
176 ecore_evas_iconified_set(ee, EINA_TRUE);
179 printf("make all windows unfullscreen\n");
180 EINA_LIST_FOREACH(ecore_evas_ews_children_get(), l, ee)
181 ecore_evas_fullscreen_set(ee, EINA_FALSE);
184 printf("make all windows fullscreen\n");
185 EINA_LIST_FOREACH(ecore_evas_ews_children_get(), l, ee)
186 ecore_evas_fullscreen_set(ee, EINA_TRUE);
190 ecore_main_loop_quit();
194 printf("Unknown command: %c\n", c);
196 return ECORE_CALLBACK_RENEW;
200 _on_delete(Ecore_Evas *ee)
202 free(ecore_evas_data_get(ee, "key"));
203 ecore_main_loop_quit();
213 if (ecore_evas_init() <= 0)
216 optional_ews_setup();
217 optional_ews_window_manager_setup();
219 /* everything should look similar to ecore_evas_basic_example */
220 ee = ecore_evas_ews_new(0, 0, 200, 200);
221 ecore_evas_title_set(ee, "Ecore Evas EWS Example");
224 ecore_evas_data_set(ee, "key", strdup("hello"));
225 ecore_evas_callback_delete_request_set(ee, _on_delete);
227 printf("Using %s engine!\n", ecore_evas_engine_name_get(ee));
229 canvas = ecore_evas_get(ee);
230 if (ecore_evas_ecore_evas_get(canvas) == ee)
231 printf("Everything is sane!\n");
233 bg = evas_object_rectangle_add(canvas);
234 evas_object_color_set(bg, 0, 0, 255, 255);
235 evas_object_resize(bg, 200, 200);
236 evas_object_show(bg);
237 ecore_evas_object_associate(ee, bg, ECORE_EVAS_OBJECT_ASSOCIATE_BASE);
239 /* moving the window should move it in the screen */
240 ecore_evas_move(ee, 50, 50);
242 ecore_main_fd_handler_add(STDIN_FILENO,
243 ECORE_FD_READ | ECORE_FD_ERROR,
247 ecore_main_loop_begin();
250 ecore_evas_shutdown();