summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBruno Dilly <bdilly@profusion.mobi>2016-12-14 15:47:20 -0200
committerBruno Dilly <bdilly@profusion.mobi>2016-12-19 14:58:35 -0200
commit60b160f47ce22f30eb62917d4d43628c6c04861e (patch)
tree075100efd5c9c1cfe49cd8f591b304c8d2b9fa9b /src
parent287486e9208687ba57529adc4bd3b33c99bfbdbb (diff)
edje/examples: add example for focus actions
Just a regular (non multiseat) focus example for actions FOCUS_SET and FOCUS_OBJECT
Diffstat (limited to 'src')
-rw-r--r--src/examples/edje/.gitignore1
-rw-r--r--src/examples/edje/Makefile.am3
-rw-r--r--src/examples/edje/edje-focus.c157
-rw-r--r--src/examples/edje/focus.edc330
4 files changed, 491 insertions, 0 deletions
diff --git a/src/examples/edje/.gitignore b/src/examples/edje/.gitignore
index 0c3b2c21c8..d3d18389ac 100644
--- a/src/examples/edje/.gitignore
+++ b/src/examples/edje/.gitignore
@@ -12,6 +12,7 @@
12/edje-dynamic-multiseat 12/edje-dynamic-multiseat
13/edje-edit-part-box 13/edje-edit-part-box
14/edje-entry 14/edje-entry
15/edje-focus
15/edje-multiseat 16/edje-multiseat
16/edje-multisense 17/edje-multisense
17/edje-perspective 18/edje-perspective
diff --git a/src/examples/edje/Makefile.am b/src/examples/edje/Makefile.am
index afa1528221..78365a4618 100644
--- a/src/examples/edje/Makefile.am
+++ b/src/examples/edje/Makefile.am
@@ -42,6 +42,7 @@ external_elm_button.edc \
42external_elm_check.edc \ 42external_elm_check.edc \
43external_elm_panes.edc \ 43external_elm_panes.edc \
44external_emotion_elm.edc \ 44external_emotion_elm.edc \
45focus.edc \
45lua_script.edc \ 46lua_script.edc \
46messages_echo.edc \ 47messages_echo.edc \
47multiseat.edc \ 48multiseat.edc \
@@ -143,6 +144,7 @@ edje-drag.c \
143edje-dynamic-multiseat.c \ 144edje-dynamic-multiseat.c \
144edje-edit-part-box.c \ 145edje-edit-part-box.c \
145edje-entry.c \ 146edje-entry.c \
147edje-focus.c \
146edje-multiseat.c \ 148edje-multiseat.c \
147edje-multisense.c \ 149edje-multisense.c \
148edje-perspective.c \ 150edje-perspective.c \
@@ -218,6 +220,7 @@ edje-drag \
218edje-dynamic-multiseat \ 220edje-dynamic-multiseat \
219edje-edit-part-box \ 221edje-edit-part-box \
220edje-entry \ 222edje-entry \
223edje-focus \
221edje-multiseat \ 224edje-multiseat \
222edje-perspective \ 225edje-perspective \
223edje-signals-messages \ 226edje-signals-messages \
diff --git a/src/examples/edje/edje-focus.c b/src/examples/edje/edje-focus.c
new file mode 100644
index 0000000000..01e9e2eeb6
--- /dev/null
+++ b/src/examples/edje/edje-focus.c
@@ -0,0 +1,157 @@
1/**
2 * Edje example demonstrating how to deal with part and objects focus.
3 *
4 * @verbatim
5 * edje_cc focus.edc && gcc -o edje-focus edje-focus.c `pkg-config --libs --cflags evas ecore ecore-evas edje`
6 * @endverbatim
7 */
8
9#ifdef HAVE_CONFIG_H
10# include "config.h"
11#else
12# define EINA_UNUSED
13#endif
14
15#ifndef PACKAGE_DATA_DIR
16#define PACKAGE_DATA_DIR "."
17#endif
18
19#include <Ecore.h>
20#include <Ecore_Evas.h>
21#include <Edje.h>
22
23#define WIDTH 400
24#define HEIGHT 400
25
26static const char *GROUPNAME = "example/main";
27static const char *EDJE_FILE = PACKAGE_DATA_DIR"/focus.edj";
28
29static void
30_on_destroy(Ecore_Evas *ee EINA_UNUSED)
31{
32 ecore_main_loop_quit();
33}
34
35static void
36_on_canvas_resize(Ecore_Evas *ee)
37{
38 Evas_Object *edje_obj;
39 int w, h;
40
41 edje_obj = ecore_evas_data_get(ee, "edje_obj");
42
43 ecore_evas_geometry_get(ee, NULL, NULL, &w, &h);
44 evas_object_resize(edje_obj, w, h);
45}
46
47static void
48_focus_part_in_cb(void *data EINA_UNUSED, Evas_Object *o EINA_UNUSED,
49 const char *emission EINA_UNUSED, const char *source)
50{
51 printf("Focus set to part %s\n", source);
52}
53
54static void
55_focus_part_out_cb(void *data EINA_UNUSED, Evas_Object *o EINA_UNUSED,
56 const char *emission EINA_UNUSED, const char *source)
57{
58 printf("Focus unset to part %s\n", source);
59}
60
61static void
62_focus_obj_in_cb(void *data EINA_UNUSED, const Efl_Event *event)
63{
64 Efl_Input_Focus *ev = event->info;
65 Evas_Object *rect = event->object;
66 /* it always will print the default seat name, since FOCUS_OBJECT
67 isn't setting a specific seat */
68 printf("Focus set to object %s (seat %s)\n", evas_object_name_get(rect),
69 efl_input_device_name_get(efl_input_device_get(ev)));
70}
71
72static void
73_focus_obj_out_cb(void *data EINA_UNUSED, const Efl_Event *event)
74{
75 Efl_Input_Focus *ev = event->info;
76 Evas_Object *rect = event->object;
77 printf("Focus unset to object %s (seat %s)\n", evas_object_name_get(rect),
78 efl_input_device_name_get(efl_input_device_get(ev)));
79}
80
81int
82main(int argc EINA_UNUSED, char *argv[] EINA_UNUSED)
83{
84 Evas_Object *edje_obj, *rect_left, *rect_right;
85 Ecore_Evas *ee;
86 Evas *evas;
87
88 if (!ecore_evas_init())
89 return EXIT_FAILURE;
90
91 if (!edje_init())
92 goto shutdown_ecore_evas;
93
94 ee = ecore_evas_new(NULL, 0, 0, WIDTH, HEIGHT, NULL);
95 if (!ee) goto shutdown_edje;
96
97 ecore_evas_callback_destroy_set(ee, _on_destroy);
98 ecore_evas_callback_resize_set(ee, _on_canvas_resize);
99 ecore_evas_title_set(ee, "Edje Focus Example");
100
101 evas = ecore_evas_get(ee);
102
103 edje_obj = edje_object_add(evas);
104
105 if (!edje_object_file_set(edje_obj, EDJE_FILE, GROUPNAME))
106 printf("failed to set file %s.\n", EDJE_FILE);
107
108 evas_object_move(edje_obj, 0, 0);
109 evas_object_resize(edje_obj, WIDTH, HEIGHT);
110 evas_object_show(edje_obj);
111 ecore_evas_data_set(ee, "edje_obj", edje_obj);
112
113 edje_object_signal_callback_add(edje_obj, "focus,part,in", "*",
114 _focus_part_in_cb, NULL);
115 edje_object_signal_callback_add(edje_obj, "focus,part,out", "*",
116 _focus_part_out_cb, NULL);
117
118 rect_left = evas_object_rectangle_add(evas);
119 evas_object_name_set(rect_left, "rect left");
120 evas_object_color_set(rect_left, 200, 200, 100, 255);
121 edje_object_part_swallow(edje_obj, "button,3", rect_left);
122
123 efl_event_callback_add(rect_left, EFL_EVENT_FOCUS_IN,
124 _focus_obj_in_cb, NULL);
125 efl_event_callback_add(rect_left, EFL_EVENT_FOCUS_OUT,
126 _focus_obj_out_cb, NULL);
127
128 rect_right = evas_object_rectangle_add(evas);
129 evas_object_name_set(rect_right, "rect right");
130 evas_object_color_set(rect_right, 100, 200, 200, 255);
131 edje_object_part_swallow(edje_obj, "button,4", rect_right);
132
133 efl_event_callback_add(rect_right, EFL_EVENT_FOCUS_IN,
134 _focus_obj_in_cb, NULL);
135 efl_event_callback_add(rect_right, EFL_EVENT_FOCUS_OUT,
136 _focus_obj_out_cb, NULL);
137
138 printf("Running example on evas engine %s\n",
139 ecore_evas_engine_name_get(ee));
140
141 ecore_evas_show(ee);
142
143 ecore_main_loop_begin();
144
145 ecore_evas_free(ee);
146 ecore_evas_shutdown();
147 edje_shutdown();
148
149 return EXIT_SUCCESS;
150
151shutdown_edje:
152 edje_shutdown();
153shutdown_ecore_evas:
154 ecore_evas_shutdown();
155
156 return EXIT_FAILURE;
157}
diff --git a/src/examples/edje/focus.edc b/src/examples/edje/focus.edc
new file mode 100644
index 0000000000..9b2ad3bec8
--- /dev/null
+++ b/src/examples/edje/focus.edc
@@ -0,0 +1,330 @@
1collections {
2
3 group {
4 name: "example/main";
5 min: 400 400;
6
7 parts {
8 part {
9 name: "bg";
10 type: RECT;
11 mouse_events: 0;
12 description {
13 state: "default" 0.0;
14 }
15 }
16
17 part {
18 name: "title";
19 type: TEXT;
20 mouse_events: 0;
21 description {
22 state: "default" 0.0;
23 color: 0 0 0 255;
24 rel1 {
25 relative: 0.0 0.0;
26 offset: 0 0;
27 to: "bg";
28 }
29 rel2 {
30 relative: 1.0 0.2;
31 offset: -1 -1;
32 to: "bg";
33 }
34 text {
35 text: "Focus Example";
36 size: 16;
37 font: "sans";
38 min: 1 1;
39 }
40 }
41 }
42
43 part {
44 name: "buttons";
45 type: RECT;
46 mouse_events: 0;
47 description {
48 state: "default" 0.0;
49 rel1.relative: 0.2 0.3;
50 rel2.relative: 0.8 0.9;
51 color: 255 255 255 0;
52 }
53 }
54
55 part {
56 name: "button_bg,1";
57 type: RECT;
58 mouse_events: 1;
59 description {
60 state: "default" 0.0;
61 rel1 {
62 to: "buttons";
63 relative: 0.1 0.1;
64 }
65 rel2 {
66 to: "buttons";
67 relative: 0.45 0.45;
68 }
69 color: 200 200 200 255;
70 }
71 description {
72 state: "focused" 0.0;
73 inherit: "default" 0.0;
74 color: 190 120 120 255;
75 }
76 }
77
78 part {
79 name: "button,1";
80 type: RECT;
81 mouse_events: 0;
82 description {
83 state: "default" 0.0;
84 rel1 {
85 to: "button_bg,1";
86 offset: 10 10;
87 }
88 rel2 {
89 to: "button_bg,1";
90 offset: -11 -11;
91 }
92 color: 200 200 200 255;
93 }
94 }
95
96 part {
97 name: "button_bg,2";
98 type: RECT;
99 mouse_events: 1;
100 description {
101 state: "default" 0.0;
102 rel1 {
103 to: "buttons";
104 relative: 0.55 0.1;
105 }
106 rel2 {
107 to: "buttons";
108 relative: 0.9 0.45;
109 }
110 color: 200 200 200 255;
111 }
112 description {
113 state: "focused" 0.0;
114 inherit: "default" 0.0;
115 color: 190 120 120 255;
116 }
117 }
118
119 part {
120 name: "button,2";
121 type: RECT;
122 mouse_events: 0;
123 description {
124 state: "default" 0.0;
125 rel1 {
126 to: "button_bg,2";
127 offset: 10 10;
128 }
129 rel2 {
130 to: "button_bg,2";
131 offset: -11 -11;
132 }
133 color: 200 200 200 255;
134 }
135 }
136
137 part {
138 name: "button_bg,3";
139 type: RECT;
140 mouse_events: 1;
141 description {
142 state: "default" 0.0;
143 rel1 {
144 to: "buttons";
145 relative: 0.1 0.55;
146 }
147 rel2 {
148 to: "buttons";
149 relative: 0.45 0.9;
150 }
151 color: 200 200 200 255;
152 }
153 description {
154 state: "focused" 0.0;
155 inherit: "default" 0.0;
156 color: 190 120 120 255;
157 }
158 }
159
160 part {
161 name: "button,3";
162 type: SWALLOW;
163 mouse_events: 0;
164 description {
165 state: "default" 0.0;
166 rel1 {
167 to: "button_bg,3";
168 offset: 10 10;
169 }
170 rel2 {
171 to: "button_bg,3";
172 offset: -11 -11;
173 }
174 }
175 }
176
177 part {
178 name: "button_bg,4";
179 type: RECT;
180 mouse_events: 1;
181 description {
182 state: "default" 0.0;
183 rel1 {
184 to: "buttons";
185 relative: 0.55 0.55;
186 }
187 rel2 {
188 to: "buttons";
189 relative: 0.9 0.9;
190 }
191 color: 200 200 200 255;
192 }
193 description {
194 state: "focused" 0.0;
195 inherit: "default" 0.0;
196 color: 190 120 120 255;
197 }
198 }
199
200 part {
201 name: "button,4";
202 type: SWALLOW;
203 mouse_events: 0;
204 description {
205 state: "default" 0.0;
206 rel1 {
207 to: "button_bg,4";
208 offset: 10 10;
209 }
210 rel2 {
211 to: "button_bg,4";
212 offset: -11 -11;
213 }
214 }
215 }
216 }
217
218 programs {
219 program {
220 name: "button,clicked,1";
221 signal: "mouse,clicked,1";
222 source: "button_bg,1";
223 action: FOCUS_SET;
224 target: "button,1";
225 after: "unfocus,objects";
226 }
227
228 program {
229 name: "button,clicked,2";
230 signal: "mouse,clicked,1";
231 source: "button_bg,2";
232 action: FOCUS_SET;
233 target: "button,2";
234 after: "unfocus,objects";
235 }
236
237 program {
238 name: "unfocus,objects";
239 action: FOCUS_OBJECT;
240 }
241
242 program {
243 name: "button,clicked,3";
244 signal: "mouse,clicked,1";
245 source: "button_bg,3";
246 action: FOCUS_OBJECT;
247 target: "button,3";
248 after: "unset,part";
249 }
250
251 program {
252 name: "button,clicked,4";
253 signal: "mouse,clicked,1";
254 source: "button_bg,4";
255 action: FOCUS_OBJECT;
256 target: "button,4";
257 after: "unset,part";
258 }
259
260 program {
261 name: "unset,part";
262 action: FOCUS_SET;
263 }
264
265 program {
266 name: "button,focused,1";
267 signal: "focus,part,in";
268 source: "button,1";
269 action: STATE_SET "focused" 0.0;
270 target: "button_bg,1";
271 }
272
273 program {
274 name: "button,focused,2";
275 signal: "focus,part,in";
276 source: "button,2";
277 action: STATE_SET "focused" 0.0;
278 target: "button_bg,2";
279 }
280
281 program {
282 name: "button,focused,3";
283 signal: "focus,part,in";
284 source: "button,3";
285 action: STATE_SET "focused" 0.0;
286 target: "button_bg,3";
287 }
288
289 program {
290 name: "button,focused,4";
291 signal: "focus,part,in";
292 source: "button,4";
293 action: STATE_SET "focused" 0.0;
294 target: "button_bg,4";
295 }
296
297 program {
298 name: "button,unfocused,1";
299 signal: "focus,part,out";
300 source: "button,1";
301 action: STATE_SET "default" 0.0;
302 target: "button_bg,1";
303 }
304
305 program {
306 name: "button,unfocused,2";
307 signal: "focus,part,out";
308 source: "button,2";
309 action: STATE_SET "default" 0.0;
310 target: "button_bg,2";
311 }
312
313 program {
314 name: "button,unfocused,3";
315 signal: "focus,part,out";
316 source: "button,3";
317 action: STATE_SET "default" 0.0;
318 target: "button_bg,3";
319 }
320
321 program {
322 name: "button,unfocused,4";
323 signal: "focus,part,out";
324 source: "button,4";
325 action: STATE_SET "default" 0.0;
326 target: "button_bg,4";
327 }
328 }
329 }
330}