2 * gcc -o win_example win_example.c `pkg-config --cflags --libs elementary ecore-x`
4 #ifdef HAVE_ELEMENTARY_X
8 #include <Elementary.h>
11 _btn_activate_cb(void *data, Evas_Object *obj, void *event)
13 elm_win_activate(data);
17 _btn_lower_cb(void *data, Evas_Object *obj, void *event)
23 _btn_raise_cb(void *data, Evas_Object *obj, void *event)
29 _btn_borderless_cb(void *data, Evas_Object *obj, void *event)
31 Eina_Bool flag = elm_win_borderless_get(data);
32 elm_win_borderless_set(data, !flag);
36 _btn_shaped_cb(void *data, Evas_Object *obj, void *event)
38 Eina_Bool flag = elm_win_shaped_get(data);
39 elm_win_shaped_set(data, !flag);
43 _btn_alpha_cb(void *data, Evas_Object *obj, void *event)
45 Eina_Bool flag = elm_win_alpha_get(data);
46 elm_win_alpha_set(data, !flag);
50 _btn_fullscreen_cb(void *data, Evas_Object *obj, void *event)
52 Eina_Bool flag = elm_win_fullscreen_get(data);
53 elm_win_fullscreen_set(data, !flag);
57 _btn_maximized_cb(void *data, Evas_Object *obj, void *event)
59 Eina_Bool flag = elm_win_maximized_get(data);
60 elm_win_maximized_set(data, !flag);
64 _btn_iconified_cb(void *data, Evas_Object *obj, void *event)
66 Eina_Bool flag = elm_win_iconified_get(data);
67 elm_win_iconified_set(data, !flag);
71 _btn_rotation_cb(void *data, Evas_Object *obj, void *event)
73 int angle = elm_win_rotation_get(data);
74 angle = (angle + 90) % 360;
75 elm_win_rotation_set(data, angle);
79 _btn_rotation_resize_cb(void *data, Evas_Object *obj, void *event)
81 int angle = elm_win_rotation_get(data);
82 angle = (angle + 90) % 360;
83 elm_win_rotation_with_resize_set(data, angle);
87 _btn_sticky_cb(void *data, Evas_Object *obj, void *event)
89 Eina_Bool flag = elm_win_sticky_get(data);
90 elm_win_sticky_set(data, !flag);
94 _yes_quit_cb(void *data, Evas_Object *obj, void *event)
100 _no_quit_cb(void *data, Evas_Object *obj, void *event)
102 evas_object_del(data);
106 _main_win_del_cb(void *data, Evas_Object *obj, void *event)
108 Evas_Object *msg, *box, *box2, *btn, *lbl, *sep;
110 msg = elm_notify_add(obj);
111 elm_notify_orient_set(msg, ELM_NOTIFY_ORIENT_CENTER);
112 elm_notify_allow_events_set(msg, EINA_FALSE);
113 evas_object_show(msg);
115 box = elm_box_add(obj);
116 evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
117 evas_object_size_hint_align_set(box, EVAS_HINT_FILL, EVAS_HINT_FILL);
118 elm_object_content_set(msg, box);
119 evas_object_show(box);
121 lbl = elm_label_add(obj);
122 elm_object_text_set(lbl, "Really want quit?");
123 evas_object_size_hint_weight_set(lbl, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
124 evas_object_size_hint_align_set(lbl, EVAS_HINT_FILL, EVAS_HINT_FILL);
125 elm_box_pack_end(box, lbl);
126 evas_object_show(lbl);
128 sep = elm_separator_add(obj);
129 elm_separator_horizontal_set(sep, EINA_TRUE);
130 elm_box_pack_end(box, sep);
131 evas_object_show(sep);
133 box2 = elm_box_add(obj);
134 elm_box_horizontal_set(box2, EINA_TRUE);
135 evas_object_size_hint_weight_set(box2, EVAS_HINT_EXPAND, 0.0);
136 evas_object_size_hint_align_set(box2, EVAS_HINT_FILL, EVAS_HINT_FILL);
137 elm_box_pack_end(box, box2);
138 evas_object_show(box2);
140 btn = elm_button_add(obj);
141 elm_object_text_set(btn, "Yes");
142 elm_box_pack_end(box2, btn);
143 evas_object_show(btn);
145 evas_object_smart_callback_add(btn, "clicked", _yes_quit_cb, NULL);
147 btn = elm_button_add(obj);
148 elm_object_text_set(btn, "No");
149 elm_box_pack_end(box2, btn);
150 evas_object_show(btn);
152 evas_object_smart_callback_add(btn, "clicked", _no_quit_cb, msg);
156 _force_focus_cb(void *data, Evas_Object *obj, void *event)
158 #ifdef HAVE_ELEMENTARY_X
159 Ecore_X_Window xwin = elm_win_xwindow_get(data);
160 ecore_x_window_focus(xwin);
165 _win_focused_cb(void *data, Evas_Object *obj, void *event)
167 const char *name = data;
168 printf("Window focused: %s\n", name);
172 elm_main(int argc, char *argv[])
174 Evas_Object *win, *win2, *bg, *bigbox, *box, *btn, *o;
177 elm_app_info_set(elm_main, "elementary", "images/logo.png");
178 win = elm_win_add(NULL, "win-example", ELM_WIN_BASIC);
179 elm_win_title_set(win, "Elm_Win Example");
180 elm_win_focus_highlight_enabled_set(win, EINA_TRUE);
181 evas_object_resize(win, 400, 400);
182 evas_object_show(win);
184 evas_object_smart_callback_add(win, "focus,in", _win_focused_cb, "mainwin");
186 evas_object_smart_callback_add(win, "delete,request", _main_win_del_cb,
189 bg = elm_bg_add(win);
190 evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
191 elm_win_resize_object_add(win, bg);
192 evas_object_show(bg);
194 bigbox = elm_box_add(win);
195 elm_box_horizontal_set(bigbox, EINA_TRUE);
196 evas_object_size_hint_weight_set(bigbox, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
197 elm_win_resize_object_add(win, bigbox);
198 evas_object_show(bigbox);
200 box = elm_box_add(win);
201 evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
202 evas_object_size_hint_align_set(box, EVAS_HINT_FILL, EVAS_HINT_FILL);
203 elm_box_pack_end(bigbox, box);
204 evas_object_show(box);
206 win2 = elm_win_add(NULL, "sub-win-example", ELM_WIN_DIALOG_BASIC);
207 elm_win_autodel_set(win2, EINA_TRUE);
208 elm_win_title_set(win2, "Managed window");
209 evas_object_show(win2);
211 evas_object_smart_callback_add(win2, "focus,in", _win_focused_cb, "managed");
213 o = elm_icon_add(win2);
214 sprintf(buf, "%s/images/logo.png", elm_app_data_dir_get());
215 elm_image_file_set(o, buf, NULL);
216 elm_image_resizable_set(o, 0, 0);
217 elm_image_no_scale_set(o, EINA_TRUE);
218 elm_win_resize_object_add(win2, o);
221 o = elm_label_add(win);
222 elm_object_text_set(o, "<b>Managed Window</b>");
223 elm_box_pack_end(box, o);
226 #define WIN_ACTION(name) \
228 btn = elm_button_add(win); \
229 elm_object_text_set(btn, #name); \
230 elm_box_pack_end(box, btn); \
231 evas_object_show(btn); \
232 evas_object_smart_callback_add(btn, "clicked", _btn_##name##_cb, win2); \
235 WIN_ACTION(activate);
238 WIN_ACTION(borderless);
241 WIN_ACTION(fullscreen);
242 WIN_ACTION(maximized);
243 WIN_ACTION(iconified);
244 WIN_ACTION(rotation);
245 WIN_ACTION(rotation_resize);
248 box = elm_box_add(win);
249 evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
250 evas_object_size_hint_align_set(box, EVAS_HINT_FILL, EVAS_HINT_FILL);
251 elm_box_pack_end(bigbox, box);
252 evas_object_show(box);
254 win2 = elm_win_add(NULL, "sub-win-example2", ELM_WIN_BASIC);
255 elm_win_autodel_set(win2, EINA_TRUE);
256 elm_win_title_set(win2, "Non-managed window");
257 elm_win_override_set(win2, EINA_TRUE);
258 evas_object_show(win2);
260 evas_object_smart_callback_add(win2, "focus,in", _win_focused_cb,
263 o = elm_bg_add(win2);
264 evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
265 elm_win_resize_object_add(win2, o);
268 bigbox = elm_box_add(win2);
269 evas_object_size_hint_weight_set(bigbox, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
270 elm_win_resize_object_add(win2, bigbox);
271 evas_object_show(bigbox);
273 o = elm_label_add(win2);
274 elm_object_text_set(o, "This window should have no borders or titlebar.<ps>"
275 "It was set in override mode, so the Window Manager<ps>"
276 "should ignore everything about it.<ps>"
277 "It's up to the program to handle it properly, and some"
278 "of the actions performed on it may not have any effect."
280 elm_box_pack_end(bigbox, o);
283 o = elm_entry_add(win2);
284 elm_object_text_set(o, "See if you can focus me");
285 elm_entry_single_line_set(o, EINA_TRUE);
286 elm_entry_scrollable_set(o, EINA_TRUE);
287 evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0);
288 evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
289 elm_box_pack_end(bigbox, o);
292 o = elm_separator_add(win2);
293 elm_separator_horizontal_set(o, EINA_TRUE);
294 elm_box_pack_end(bigbox, o);
297 o = elm_button_add(win2);
298 elm_object_text_set(o, "Focus me");
299 elm_box_pack_end(bigbox, o);
302 evas_object_smart_callback_add(o, "clicked", _force_focus_cb, win2);
304 o = elm_label_add(win);
305 elm_object_text_set(o, "<b>Override Window</b>");
306 elm_box_pack_end(box, o);
309 WIN_ACTION(activate);
312 WIN_ACTION(borderless);
315 WIN_ACTION(fullscreen);
316 WIN_ACTION(maximized);
317 WIN_ACTION(iconified);
318 WIN_ACTION(rotation);
319 WIN_ACTION(rotation_resize);