summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBruno Dilly <bdilly@profusion.mobi>2016-12-05 20:41:33 -0200
committerBruno Dilly <bdilly@profusion.mobi>2016-12-19 14:58:35 -0200
commitf34220f0890f5107a330addfc06bbe02c313602a (patch)
tree4ad677dbe5af018fe3452395d9aaa2fedb967ff4 /src
parentc6399665ddb0f719df6514b78c9cf6f685dfbb0d (diff)
examples/edje: add dynamic seats example
It's an example of how themes can be implemented even if the number of seats using the UI is unknown, and how it can be done using scripts or C code.
Diffstat (limited to 'src')
-rw-r--r--src/examples/edje/.gitignore1
-rw-r--r--src/examples/edje/Makefile.am5
-rw-r--r--src/examples/edje/dynamic_multiseat.edc279
-rw-r--r--src/examples/edje/edje-dynamic-multiseat.c136
4 files changed, 420 insertions, 1 deletions
diff --git a/src/examples/edje/.gitignore b/src/examples/edje/.gitignore
index a10bdf9061..0c3b2c21c8 100644
--- a/src/examples/edje/.gitignore
+++ b/src/examples/edje/.gitignore
@@ -9,6 +9,7 @@
9/edje-codegen-example 9/edje-codegen-example
10/edje-color-class 10/edje-color-class
11/edje-drag 11/edje-drag
12/edje-dynamic-multiseat
12/edje-edit-part-box 13/edje-edit-part-box
13/edje-entry 14/edje-entry
14/edje-multiseat 15/edje-multiseat
diff --git a/src/examples/edje/Makefile.am b/src/examples/edje/Makefile.am
index 6198ccf125..afa1528221 100644
--- a/src/examples/edje/Makefile.am
+++ b/src/examples/edje/Makefile.am
@@ -23,6 +23,7 @@ box_example.edc \
23codegen.edc \ 23codegen.edc \
24color-class.edc \ 24color-class.edc \
25drag.edc \ 25drag.edc \
26dynamic_multiseat.edc \
26edje-group.edc \ 27edje-group.edc \
27edje-nested.edc \ 28edje-nested.edc \
28edje-threshold.edc \ 29edje-threshold.edc \
@@ -139,6 +140,7 @@ edje-box2.c \
139edje-codegen-example.c \ 140edje-codegen-example.c \
140edje-color-class.c \ 141edje-color-class.c \
141edje-drag.c \ 142edje-drag.c \
143edje-dynamic-multiseat.c \
142edje-edit-part-box.c \ 144edje-edit-part-box.c \
143edje-entry.c \ 145edje-entry.c \
144edje-multiseat.c \ 146edje-multiseat.c \
@@ -212,7 +214,8 @@ edje-box \
212edje-box2 \ 214edje-box2 \
213edje-codegen-example \ 215edje-codegen-example \
214edje-color-class \ 216edje-color-class \
215edje-drag\ 217edje-drag \
218edje-dynamic-multiseat \
216edje-edit-part-box \ 219edje-edit-part-box \
217edje-entry \ 220edje-entry \
218edje-multiseat \ 221edje-multiseat \
diff --git a/src/examples/edje/dynamic_multiseat.edc b/src/examples/edje/dynamic_multiseat.edc
new file mode 100644
index 0000000000..d512f03f72
--- /dev/null
+++ b/src/examples/edje/dynamic_multiseat.edc
@@ -0,0 +1,279 @@
1collections {
2
3 color_classes {
4 color_class {
5 name: "button_bg,1";
6 color: 200 200 200 255;
7 }
8 color_class {
9 name: "button_bg,2";
10 color: 200 200 200 255;
11 }
12 color_class {
13 name: "button_bg,3";
14 color: 200 200 200 255;
15 }
16 color_class {
17 name: "button_bg,4";
18 color: 200 200 200 255;
19 }
20 }
21
22 group {
23 name: "example/main";
24 min: 400 400;
25
26 parts {
27 part {
28 name: "bg";
29 type: RECT;
30 mouse_events: 0;
31 description {
32 state: "default" 0.0;
33 }
34 }
35
36 part {
37 name: "title";
38 type: TEXT;
39 mouse_events: 0;
40 description {
41 state: "default" 0.0;
42 color: 0 0 0 255;
43 rel1 {
44 relative: 0.0 0.0;
45 offset: 0 0;
46 to: "bg";
47 }
48 rel2 {
49 relative: 1.0 0.2;
50 offset: -1 -1;
51 to: "bg";
52 }
53 text {
54 text: "Dynamic Multiseat Example";
55 size: 16;
56 font: "sans";
57 min: 1 1;
58 }
59 }
60 }
61
62 part {
63 name: "buttons";
64 type: RECT;
65 mouse_events: 0;
66 description {
67 state: "default" 0.0;
68 rel1.relative: 0.2 0.3;
69 rel2.relative: 0.8 0.9;
70 color: 255 255 255 0;
71 }
72 }
73
74 part {
75 name: "button_bg,1";
76 type: RECT;
77 mouse_events: 1;
78 description {
79 state: "default" 0.0;
80 rel1 {
81 to: "buttons";
82 relative: 0.1 0.1;
83 }
84 rel2 {
85 to: "buttons";
86 relative: 0.45 0.45;
87 }
88 color_class: "button_bg,1";
89 }
90 }
91
92 part {
93 name: "button1";
94 type: RECT;
95 mouse_events: 0;
96 description {
97 state: "default" 0.0;
98 rel1 {
99 to: "button_bg,1";
100 offset: 10 10;
101 }
102 rel2 {
103 to: "button_bg,1";
104 offset: -11 -11;
105 }
106 color: 200 200 200 255;
107 }
108 }
109
110 part {
111 name: "button_bg,2";
112 type: RECT;
113 mouse_events: 1;
114 description {
115 state: "default" 0.0;
116 rel1 {
117 to: "buttons";
118 relative: 0.55 0.1;
119 }
120 rel2 {
121 to: "buttons";
122 relative: 0.9 0.45;
123 }
124 color_class: "button_bg,2";
125 }
126 }
127
128 part {
129 name: "button2";
130 type: RECT;
131 mouse_events: 0;
132 description {
133 state: "default" 0.0;
134 rel1 {
135 to: "button_bg,2";
136 offset: 10 10;
137 }
138 rel2 {
139 to: "button_bg,2";
140 offset: -11 -11;
141 }
142 color: 200 200 200 255;
143 }
144 }
145
146 part {
147 name: "button_bg,3";
148 type: RECT;
149 mouse_events: 1;
150 description {
151 state: "default" 0.0;
152 rel1 {
153 to: "buttons";
154 relative: 0.1 0.55;
155 }
156 rel2 {
157 to: "buttons";
158 relative: 0.45 0.9;
159 }
160 color_class: "button_bg,3";
161 }
162 }
163
164 part {
165 name: "button3";
166 type: RECT;
167 mouse_events: 0;
168 description {
169 state: "default" 0.0;
170 rel1 {
171 to: "button_bg,3";
172 offset: 10 10;
173 }
174 rel2 {
175 to: "button_bg,3";
176 offset: -11 -11;
177 }
178 color: 200 200 200 255;
179 }
180 }
181
182 part {
183 name: "button_bg,4";
184 type: RECT;
185 mouse_events: 1;
186 description {
187 state: "default" 0.0;
188 rel1 {
189 to: "buttons";
190 relative: 0.55 0.55;
191 }
192 rel2 {
193 to: "buttons";
194 relative: 0.9 0.9;
195 }
196 color_class: "button_bg,4";
197 }
198 }
199
200 part {
201 name: "button4";
202 type: RECT;
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 color: 200 200 200 255;
215 }
216 }
217 }
218
219 script {
220 public red;
221 public green;
222 public blue;
223 public seat_count;
224 }
225
226 programs {
227 program {
228 name: "seat,added";
229 signal: "seat,added,*";
230 source: "";
231 script {
232 new seat_name[128];
233 new buf[256];
234 new r, g, b;
235
236 r = rand() * 255 / 65535;
237 append_int(red, r);
238 g = rand() * 255 / 65535;
239 append_int(green, g);
240 b = rand() * 255 / 65535;
241 append_int(blue, b);
242
243 set_int(seat_count, get_int(seat_count) + 1);
244
245 strncpy(seat_name, sig[strlen("seat,added,")],
246 strchr(sig[strlen("seat,added,")], ","));
247 snprintf(buf, 128, "seat,color,%s,r=%i,g=%i,b=%i", seat_name,
248 r, g, b);
249 emit(buf, "theme");
250 }
251 }
252
253 program {
254 name: "button,in";
255 signal: "mouse,in,*";
256 source: "button_bg,*";
257 script {
258 new idx, r, g, b;
259
260 idx = atoi(sig[strlen("mouse,in,seat")]) - 1;
261 r = fetch_int(red, idx);
262 g = fetch_int(green, idx);
263 b = fetch_int(blue, idx);
264
265 set_color_class(src, r, g, b, 255);
266 }
267 }
268
269 program {
270 name: "button,out";
271 signal: "mouse,out,*";
272 source: "button_bg,*";
273 script {
274 set_color_class(src, 200, 200, 200, 255);
275 }
276 }
277 }
278 }
279}
diff --git a/src/examples/edje/edje-dynamic-multiseat.c b/src/examples/edje/edje-dynamic-multiseat.c
new file mode 100644
index 0000000000..37bde33f99
--- /dev/null
+++ b/src/examples/edje/edje-dynamic-multiseat.c
@@ -0,0 +1,136 @@
1/**
2 * Edje example demonstrating how to use multiseat features following
3 * a dynamic approach.
4 *
5 * It's an example of how themes can be implemented even if the number
6 * of seats using the UI is unknown.
7 *
8 * You'll need at least one Evas engine built for it (excluding the
9 * buffer one) that supports multiseat. It may be wayland or
10 * X11 with VNC support. Using other engines will lead you to a
11 * situation where all seats are reported as the same one ("default").
12 *
13 * @verbatim
14 * edje_cc dynamic-multiseat.edc && gcc -o edje-dynamic-multiseat edje-dynamic-multiseat.c `pkg-config --libs --cflags evas ecore ecore-evas edje`
15 * @endverbatim
16 */
17
18#ifdef HAVE_CONFIG_H
19# include "config.h"
20#else
21# define EINA_UNUSED
22#endif
23
24#ifndef PACKAGE_DATA_DIR
25#define PACKAGE_DATA_DIR "."
26#endif
27
28#include <Ecore.h>
29#include <Ecore_Evas.h>
30#include <Edje.h>
31
32#define WIDTH 400
33#define HEIGHT 400
34
35static const char *GROUPNAME = "example/main";
36static const char *EDJE_FILE = PACKAGE_DATA_DIR"/dynamic_multiseat.edj";
37
38static void
39_on_destroy(Ecore_Evas *ee EINA_UNUSED)
40{
41 ecore_main_loop_quit();
42}
43
44static void
45_on_canvas_resize(Ecore_Evas *ee)
46{
47 Evas_Object *bg;
48 Evas_Object *edje_obj;
49 int w, h;
50
51 bg = ecore_evas_data_get(ee, "background");
52 edje_obj = ecore_evas_data_get(ee, "edje_obj");
53
54 ecore_evas_geometry_get(ee, NULL, NULL, &w, &h);
55 evas_object_resize(bg, w, h);
56 evas_object_resize(edje_obj, w, h);
57}
58
59static void
60_edje_seat_cb(void *data EINA_UNUSED, Evas_Object *o EINA_UNUSED, const char *emission, const char *source EINA_UNUSED)
61{
62 const char *sig;
63
64 sig = emission + strlen("seat,");
65 printf("Device %s\n", sig);
66}
67
68static void
69_print_msg_cb(void *data EINA_UNUSED, Evas_Object *o EINA_UNUSED, const char *emission, const char *source EINA_UNUSED)
70{
71 printf("Info: %s\n", emission);
72}
73
74int
75main(int argc EINA_UNUSED, char *argv[] EINA_UNUSED)
76{
77 Evas_Object *edje_obj, *bg;
78 Ecore_Evas *ee;
79 Evas *evas;
80
81 if (!ecore_evas_init())
82 return EXIT_FAILURE;
83
84 if (!edje_init())
85 goto shutdown_ecore_evas;
86
87 ee = ecore_evas_new(NULL, 0, 0, WIDTH, HEIGHT, NULL);
88 if (!ee) goto shutdown_edje;
89
90 ecore_evas_callback_destroy_set(ee, _on_destroy);
91 ecore_evas_callback_resize_set(ee, _on_canvas_resize);
92 ecore_evas_title_set(ee, "Edje Dynamic Multiseat Example");
93
94 evas = ecore_evas_get(ee);
95
96 bg = evas_object_rectangle_add(evas);
97 evas_object_color_set(bg, 255, 255, 255, 255);
98 evas_object_resize(bg, WIDTH, HEIGHT);
99 evas_object_show(bg);
100 ecore_evas_data_set(ee, "background", bg);
101
102 edje_obj = edje_object_add(evas);
103
104 if (!edje_object_file_set(edje_obj, EDJE_FILE, GROUPNAME))
105 printf("failed to set file %s.\n", EDJE_FILE);
106
107 evas_object_move(edje_obj, 0, 0);
108 evas_object_resize(edje_obj, WIDTH, HEIGHT);
109 evas_object_show(edje_obj);
110 ecore_evas_data_set(ee, "edje_obj", edje_obj);
111
112 edje_object_signal_callback_add(edje_obj, "seat,*", "",
113 _edje_seat_cb, NULL);
114 edje_object_signal_callback_add(edje_obj, "*", "theme",
115 _print_msg_cb, NULL);
116
117 printf("Running example on evas engine %s\n",
118 ecore_evas_engine_name_get(ee));
119
120 ecore_evas_show(ee);
121
122 ecore_main_loop_begin();
123
124 ecore_evas_free(ee);
125 ecore_evas_shutdown();
126 edje_shutdown();
127
128 return EXIT_SUCCESS;
129
130shutdown_edje:
131 edje_shutdown();
132shutdown_ecore_evas:
133 ecore_evas_shutdown();
134
135 return EXIT_FAILURE;
136}