aboutsummaryrefslogtreecommitdiffstats
path: root/src/bin/elementary/test_conform_indicator.c
blob: d7c13b9e7b8dc1e9f99d76662c80b862a4fcf5fd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
#ifdef HAVE_CONFIG_H
# include "elementary_config.h"
#endif
#include <Elementary.h>

static int vis = 0;
static int rotate_with_resize = 0;
static Evas_Object *win_port = NULL;
static Evas_Object *win_land = NULL;

static void
_rot_0(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
   Evas_Object *win = data;
   if (rotate_with_resize)
     elm_win_rotation_with_resize_set(win, 0);
   else
     elm_win_rotation_set(win, 0);
}

static void
_rot_90(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
   Evas_Object *win = data;
   if (rotate_with_resize)
     elm_win_rotation_with_resize_set(win, 90);
   else
     elm_win_rotation_set(win, 90);
}

static void
_rot_180(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
   Evas_Object *win = data;
   if (rotate_with_resize)
     elm_win_rotation_with_resize_set(win, 180);
   else
     elm_win_rotation_set(win, 180);
}

static void
_rot_270(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
   Evas_Object *win = data;
   if (rotate_with_resize)
     elm_win_rotation_with_resize_set(win, 270);
   else
     elm_win_rotation_set(win, 270);
}

static void
_visible_change_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
   Evas_Object *win = data;

   printf("visible change before = %d\n", vis);
   if (vis == 0)
     {
        elm_win_indicator_mode_set(win, ELM_WIN_INDICATOR_SHOW);
        vis = 1;
     }
   else
     {
        elm_win_indicator_mode_set(win, ELM_WIN_INDICATOR_HIDE);
        vis = 0;
     }

   /*Add App code here*/
   printf("visible change after = %d\n", vis);
}

static void
_launch_conformant_indicator_window_btn_cb(void *data EINA_UNUSED,
                                           Evas_Object *obj EINA_UNUSED,
                                           void *event_info EINA_UNUSED)
{
   Evas_Object *win, *conform, *bt, *bx;
   Evas_Object *plug_port = NULL, *plug_land = NULL;

   win = elm_win_util_standard_add("conformant-indicator",
                                   "Conformant Indicator");
   elm_win_autodel_set(win, EINA_TRUE);
   elm_win_conformant_set(win, EINA_TRUE);

   //Create conformant
   conform = elm_conformant_add(win);
   evas_object_size_hint_weight_set(conform, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
   elm_win_resize_object_add(win, conform);
   evas_object_show(conform);

   bx = elm_box_add(conform);
   elm_object_content_set(conform, bx);
   evas_object_show(bx);

   bt = elm_button_add(bx);
   elm_object_text_set(bt, "Rot 0");
   evas_object_smart_callback_add(bt, "clicked", _rot_0, win);
   evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, 0.0);
   evas_object_size_hint_fill_set(bt, EVAS_HINT_FILL, EVAS_HINT_FILL);
   elm_box_pack_end(bx, bt);
   evas_object_show(bt);

   bt = elm_button_add(bx);
   elm_object_text_set(bt, "Rot 90");
   evas_object_smart_callback_add(bt, "clicked", _rot_90, win);
   evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, 0.0);
   evas_object_size_hint_fill_set(bt, EVAS_HINT_FILL, EVAS_HINT_FILL);
   elm_box_pack_end(bx, bt);
   evas_object_show(bt);

   bt = elm_button_add(bx);
   elm_object_text_set(bt, "Rot 180");
   evas_object_smart_callback_add(bt, "clicked", _rot_180, win);
   evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, 0.0);
   evas_object_size_hint_fill_set(bt, EVAS_HINT_FILL, EVAS_HINT_FILL);
   elm_box_pack_end(bx, bt);
   evas_object_show(bt);

   bt = elm_button_add(bx);
   elm_object_text_set(bt, "Rot 270");
   evas_object_smart_callback_add(bt, "clicked", _rot_270, win);
   evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, 0.0);
   evas_object_size_hint_fill_set(bt, EVAS_HINT_FILL, EVAS_HINT_FILL);
   elm_box_pack_end(bx, bt);
   evas_object_show(bt);

   /* portrait plug */
   plug_port = elm_plug_add(bx);
   if (!plug_port)
     {
        printf("fail to create plug to server [elm_indicator_portrait]\n");
        evas_object_del(win);
        return;
     }

   if (!elm_plug_connect(plug_port, "elm_indicator_portrait", 0, EINA_FALSE))
     {
        printf("fail to connect to server [elm_indicator_portraits]\n");
        evas_object_del(win);
        return;
     }
   evas_object_size_hint_weight_set(plug_port, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
   evas_object_size_hint_align_set(plug_port, EVAS_HINT_FILL, EVAS_HINT_FILL);
   evas_object_show(plug_port);
   elm_box_pack_end(bx, plug_port);

   /* landscape plug */
   plug_land = elm_plug_add(bx);
   if (!plug_land)
     {
        printf("fail to create plug to server [elm_indicator_landscape]\n");
        evas_object_del(win);
        return;
     }
   if (!elm_plug_connect(plug_land, "elm_indicator_landscape", 0, EINA_FALSE))
     {
        printf("fail to connect to server [elm_indicator_landscape]\n");
        evas_object_del(win);
        return;
     }
   evas_object_size_hint_weight_set(plug_land, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
   evas_object_size_hint_align_set(plug_land, EVAS_HINT_FILL, EVAS_HINT_FILL);
   evas_object_show(plug_land);
   elm_box_pack_end(bx, plug_land);

   bt = elm_button_add(bx);
   elm_object_text_set(bt, "Show/Hide");
   evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, 0);
   evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, EVAS_HINT_FILL);
   elm_box_pack_end(bx, bt);
   evas_object_show(bt);
   evas_object_smart_callback_add(bt, "clicked", _visible_change_cb, win);

   evas_object_resize(win, 400, 600);
   evas_object_show(win);
}

static void
_mouse_down_cb(void *data, Evas *evas EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info)
{
   Evas_Event_Mouse_Down *ev = event_info;
   Evas_Object *sub_obj = data;

   printf("\nAPP mouse down [%d]x[%d] obj=%p type=%s\n", ev->canvas.x, ev->canvas.y,sub_obj,evas_object_type_get(sub_obj));

   evas_object_move(sub_obj, ev->canvas.x, ev->canvas.y);
}

static void
_mouse_move_cb(void *data, Evas *evas EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info)
{
   Evas_Event_Mouse_Move *ev = event_info;
   Evas_Object *sub_obj = data;
   if (!ev->buttons) return;

   printf("APP mouse move [%d]x[%d] obj=%p type=%s\n", ev->cur.canvas.x, ev->cur.canvas.y,sub_obj,evas_object_type_get(sub_obj));
   evas_object_move(sub_obj, ev->cur.canvas.x, ev->cur.canvas.y);
}

static void
_fill_portrait(Evas_Object *win)
{
   Evas_Object *bg, *btn;

   bg = elm_bg_add(win);
   evas_object_resize(bg, 720, 60);
   elm_bg_color_set(bg, 221, 187, 187);
   evas_object_show(bg);

   btn = elm_button_add(win);
   if (!btn)
     {
        printf("fail to elm_button_add() \n");
        return;
     }

   elm_object_text_set(btn, "portrait");

   evas_object_resize(btn, 200, 50);
   evas_object_move(btn, 260, 0);
   evas_object_show(btn);

   // This checks whether the indicator gets mouse event from application correctly
   evas_object_event_callback_add(bg, EVAS_CALLBACK_MOUSE_DOWN, _mouse_down_cb, btn);
   evas_object_event_callback_add(bg, EVAS_CALLBACK_MOUSE_MOVE, _mouse_move_cb, btn);
}

static void
_fill_landscape(Evas_Object *win)
{
   Evas_Object *bg, *btn;

   bg = elm_bg_add(win);
   evas_object_resize(bg, 1280, 60);
   elm_bg_color_set(bg, 207, 255, 255);
   evas_object_show(bg);

   btn = elm_button_add(win);
   if (!btn)
     {
        printf("fail to elm_button_add() \n");
        return;
     }

   elm_object_text_set(btn, "landscape");

   evas_object_resize(btn, 200, 50);
   evas_object_move(btn, 580, 0);
   evas_object_show(btn);

   // This checks whether the indicator gets mouse event from application correctly
   evas_object_event_callback_add(bg, EVAS_CALLBACK_MOUSE_DOWN, _mouse_down_cb, btn);
   evas_object_event_callback_add(bg, EVAS_CALLBACK_MOUSE_MOVE, _mouse_move_cb, btn);
}

static Evas_Object *
_create_portrait(void)
{
   const char *port_indi_name;

   win_port = elm_win_add(NULL, "portrait_indicator", ELM_WIN_SOCKET_IMAGE);
   if (!win_port)
     {
        printf("fail to create a portrait indicator window\n");
        return NULL;
     }
   elm_win_autodel_set(win_port, EINA_TRUE);

   port_indi_name = elm_config_indicator_service_get(0);
   if (!port_indi_name)
     {
        printf("indicator has no portrait service name: use default name\n");
        port_indi_name = "elm_indicator_portrait";
     }

   if (!elm_win_socket_listen(win_port, port_indi_name, 0, EINA_FALSE))
     {
        printf("failed to listen portrait window socket.\n");
        evas_object_del(win_port);
        return NULL;
     }

   elm_win_title_set(win_port, "win sock test:port");
   elm_win_borderless_set(win_port, EINA_TRUE);

   evas_object_move(win_port, 0, 0);
   evas_object_resize(win_port, 720, 60);

   _fill_portrait(win_port);

   return win_port;
}

static Evas_Object *
_create_landscape(void)
{
   const char *land_indi_name;

   win_land = elm_win_add(NULL, "win_socket_test:land", ELM_WIN_SOCKET_IMAGE);
   if (!win_land)
     {
        printf("fail to create a landscape indicator window\n");
        return NULL;
     }
   elm_win_autodel_set(win_land, EINA_TRUE);

   land_indi_name = elm_config_indicator_service_get(90);
   if (!land_indi_name)
     {
        printf("indicator has no landscape service name: use default name\n");
        land_indi_name = "elm_indicator_landscape";
     }

   if (!elm_win_socket_listen(win_land, land_indi_name, 0, 0))
     {
        printf("fail to listen landscape window socket.\n");
        evas_object_del(win_land);
        return NULL;
     }

   elm_win_title_set(win_land, "win sock test:land");
   elm_win_borderless_set(win_land, EINA_TRUE);

   evas_object_move(win_land, 0, 0);
   evas_object_resize(win_land, 1280, 60);

   _fill_landscape(win_land);

   return win_land;
}

static void
_indicator_service_start_btn_cb(void *data, Evas_Object *obj EINA_UNUSED,
                                void *event EINA_UNUSED)
{
   elm_object_disabled_set(data, EINA_TRUE);

   win_port = _create_portrait();
   if (!win_port) return;

   win_land = _create_landscape();
   if (!win_land) return;

   evas_object_show(win_port);
   evas_object_show(win_land);

}

void
test_conformant_indicator(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED,
                          void *event EINA_UNUSED)
{
   Evas_Object *win, *btn, *bx;

   win = elm_win_util_standard_add("conformant-indicator-service",
                                   "Conformant Indicator Service");
   elm_win_autodel_set(win, EINA_TRUE);

   bx = elm_box_add(win);
   evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
   elm_win_resize_object_add(win, bx);
   evas_object_show(bx);

   btn = elm_button_add(win);
   elm_object_text_set(btn, "Start Indicator Service");
   evas_object_size_hint_weight_set(btn, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
   evas_object_size_hint_align_set(btn, EVAS_HINT_FILL, EVAS_HINT_FILL);
   elm_box_pack_end(bx, btn);
   evas_object_show(btn);
   evas_object_smart_callback_add(btn, "clicked",
                                  _indicator_service_start_btn_cb, btn);

   btn = elm_button_add(win);
   elm_object_text_set(btn, "Launch Conformant Indicator Window");
   evas_object_size_hint_weight_set(btn, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
   evas_object_size_hint_align_set(btn, EVAS_HINT_FILL, EVAS_HINT_FILL);
   elm_box_pack_end(bx, btn);
   evas_object_show(btn);
   evas_object_smart_callback_add(btn, "clicked",
                                  _launch_conformant_indicator_window_btn_cb, NULL);

   evas_object_resize(win, 200, 200);
   evas_object_show(win);
}