Upstream merge
[framework/uifw/ecore.git] / src / lib / ecore_evas / ecore_evas_wayland_egl.c
1 #ifdef HAVE_CONFIG_H
2 # include "config.h"
3 #endif
4
5 #define LOGFNS 1
6
7 #ifdef LOGFNS
8 # include <stdio.h>
9 # define LOGFN(fl, ln, fn) \
10    printf("-ECORE_EVAS-WL: %25s: %5i - %s\n", fl, ln, fn);
11 #else
12 # define LOGFN(fl, ln, fn)
13 #endif
14
15 #ifdef BUILD_ECORE_EVAS_WAYLAND_EGL
16 # include <stdlib.h>
17 # include <string.h>
18 # include <unistd.h>
19 # include <sys/types.h>
20 # include <sys/mman.h>
21 #endif
22
23 #include <Eina.h>
24 #include <Evas.h>
25 #include <Ecore.h>
26
27 #include "ecore_evas_private.h"
28 #include "Ecore_Evas.h"
29
30 #ifdef BUILD_ECORE_EVAS_WAYLAND_EGL
31 # include <Evas_Engine_Wayland_Egl.h>
32 # include <Ecore_Wayland.h>
33
34 /* local structures */
35 typedef struct _EE_Wl_Smart_Data EE_Wl_Smart_Data;
36 struct _EE_Wl_Smart_Data 
37 {
38    Evas_Object *frame;
39    Evas_Object *text;
40    Evas_Coord x, y, w, h;
41 };
42
43 /* local function prototypes */
44 static int _ecore_evas_wl_init(void);
45 static int _ecore_evas_wl_shutdown(void);
46 static void _ecore_evas_wl_pre_free(Ecore_Evas *ee);
47 static void _ecore_evas_wl_free(Ecore_Evas *ee);
48 static void _ecore_evas_wl_callback_resize_set(Ecore_Evas *ee, void (*func)(Ecore_Evas *ee));
49 static void _ecore_evas_wl_callback_move_set(Ecore_Evas *ee, void (*func)(Ecore_Evas *ee));
50 static void _ecore_evas_wl_callback_delete_request_set(Ecore_Evas *ee, void (*func)(Ecore_Evas *ee));
51 static void _ecore_evas_wl_callback_focus_in_set(Ecore_Evas *ee, void (*func)(Ecore_Evas *ee));
52 static void _ecore_evas_wl_callback_focus_out_set(Ecore_Evas *ee, void (*func)(Ecore_Evas *ee));
53 static void _ecore_evas_wl_callback_mouse_in_set(Ecore_Evas *ee, void (*func)(Ecore_Evas *ee));
54 static void _ecore_evas_wl_callback_mouse_out_set(Ecore_Evas *ee, void (*func)(Ecore_Evas *ee));
55 static void _ecore_evas_wl_move(Ecore_Evas *ee, int x, int y);
56 static void _ecore_evas_wl_resize(Ecore_Evas *ee, int w, int h);
57 static void _ecore_evas_wl_show(Ecore_Evas *ee);
58 static void _ecore_evas_wl_hide(Ecore_Evas *ee);
59 static void _ecore_evas_wl_raise(Ecore_Evas *ee);
60 static void _ecore_evas_wl_title_set(Ecore_Evas *ee, const char *title);
61 static void _ecore_evas_wl_name_class_set(Ecore_Evas *ee, const char *n, const char *c);
62 static void _ecore_evas_wl_size_min_set(Ecore_Evas *ee, int w, int h);
63 static void _ecore_evas_wl_size_max_set(Ecore_Evas *ee, int w, int h);
64 static void _ecore_evas_wl_size_base_set(Ecore_Evas *ee, int w, int h);
65 static void _ecore_evas_wl_size_step_set(Ecore_Evas *ee, int w, int h);
66 static void _ecore_evas_wl_layer_set(Ecore_Evas *ee, int layer);
67 static void _ecore_evas_wl_iconified_set(Ecore_Evas *ee, int iconify);
68 static void _ecore_evas_wl_maximized_set(Ecore_Evas *ee, int max);
69 static void _ecore_evas_wl_fullscreen_set(Ecore_Evas *ee, int full);
70 static void _ecore_evas_wl_ignore_events_set(Ecore_Evas *ee, int ignore);
71 static void _ecore_evas_wl_alpha_set(Ecore_Evas *ee, int alpha);
72 static void _ecore_evas_wl_transparent_set(Ecore_Evas *ee, int transparent);
73 static int _ecore_evas_wl_render(Ecore_Evas *ee);
74 static void _ecore_evas_wl_screen_geometry_get(const Ecore_Evas *ee __UNUSED__, int *x, int *y, int *w, int *h);
75
76 static Eina_Bool _ecore_evas_wl_cb_mouse_in(void *data __UNUSED__, int type __UNUSED__, void *event);
77 static Eina_Bool _ecore_evas_wl_cb_mouse_out(void *data __UNUSED__, int type __UNUSED__, void *event);
78 static Eina_Bool _ecore_evas_wl_cb_focus_in(void *data __UNUSED__, int type __UNUSED__, void *event);
79 static Eina_Bool _ecore_evas_wl_cb_focus_out(void *data __UNUSED__, int type __UNUSED__, void *event);
80 static Eina_Bool _ecore_evas_wl_cb_window_configure(void *data __UNUSED__, int type __UNUSED__, void *event);
81
82 /* SMART stuff for frame */
83 static Evas_Smart *_ecore_evas_wl_smart = NULL;
84
85 static void _ecore_evas_wl_smart_init(void);
86 static void _ecore_evas_wl_smart_add(Evas_Object *obj);
87 static void _ecore_evas_wl_smart_del(Evas_Object *obj);
88 static void _ecore_evas_wl_smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h);
89 static void _ecore_evas_wl_smart_show(Evas_Object *obj);
90 static void _ecore_evas_wl_smart_hide(Evas_Object *obj);
91
92 static Evas_Object *_ecore_evas_wl_frame_add(Evas *evas);
93
94 /* local variables */
95 static int _ecore_evas_wl_init_count = 0;
96 static Ecore_Event_Handler *_ecore_evas_wl_event_hdls[5];
97
98 static Ecore_Evas_Engine_Func _ecore_wl_engine_func = 
99 {
100    _ecore_evas_wl_free,
101    _ecore_evas_wl_callback_resize_set,
102    _ecore_evas_wl_callback_move_set,
103    NULL, 
104    NULL,
105    _ecore_evas_wl_callback_delete_request_set,
106    NULL,
107    _ecore_evas_wl_callback_focus_in_set,
108    _ecore_evas_wl_callback_focus_out_set,
109    _ecore_evas_wl_callback_mouse_in_set,
110    _ecore_evas_wl_callback_mouse_out_set,
111    NULL, // sticky_set
112    NULL, // unsticky_set
113    NULL, // pre_render_set
114    NULL, // post_render_set
115    _ecore_evas_wl_move,
116    NULL, // managed_move
117    _ecore_evas_wl_resize,
118    NULL, // move_resize
119    NULL, // rotation_set
120    NULL, // shaped_set
121    _ecore_evas_wl_show,
122    _ecore_evas_wl_hide,
123    _ecore_evas_wl_raise,
124    NULL, // lower
125    NULL, // activate
126    _ecore_evas_wl_title_set,
127    _ecore_evas_wl_name_class_set,
128    _ecore_evas_wl_size_min_set,
129    _ecore_evas_wl_size_max_set,
130    _ecore_evas_wl_size_base_set,
131    _ecore_evas_wl_size_step_set,
132    NULL, // object_cursor_set
133    _ecore_evas_wl_layer_set,
134    NULL, // focus set
135    _ecore_evas_wl_iconified_set,
136    NULL, // borderless set
137    NULL, // override set
138    _ecore_evas_wl_maximized_set,
139    _ecore_evas_wl_fullscreen_set,
140    NULL, // func avoid_damage set
141    NULL, // func withdrawn set
142    NULL, // func sticky set
143    _ecore_evas_wl_ignore_events_set,
144    _ecore_evas_wl_alpha_set,
145    _ecore_evas_wl_transparent_set,
146    NULL, // func profiles set
147    NULL,
148    NULL,
149    NULL,
150    NULL,
151    NULL,
152    NULL,
153    _ecore_evas_wl_render, 
154    _ecore_evas_wl_screen_geometry_get
155 };
156
157 /* external variables */
158
159 /* external functions */
160 EAPI Ecore_Evas *
161 ecore_evas_wayland_egl_new(const char *disp_name, unsigned int parent, int x, int y, int w, int h, Eina_Bool frame)
162 {
163    Ecore_Wl_Window *p = NULL;
164    Evas_Engine_Info_Wayland_Egl *einfo;
165    Ecore_Evas *ee;
166    int method = 0, count = 0;
167
168    LOGFN(__FILE__, __LINE__, __FUNCTION__);
169
170    if (!(method = evas_render_method_lookup("wayland_egl")))
171      {
172         ERR("Render method lookup failed for Wayland_Egl");
173         return NULL;
174      }
175
176    count = ecore_wl_init(disp_name);
177    if (!count)
178      {
179         ERR("Failed to initialize Ecore_Wayland");
180         return NULL;
181      }
182    else if (count == 1)
183      ecore_wl_display_iterate();
184
185    if (!(ee = calloc(1, sizeof(Ecore_Evas))))
186      {
187         ERR("Failed to allocate Ecore_Evas");
188         ecore_wl_shutdown();
189         return NULL;
190      }
191
192    ECORE_MAGIC_SET(ee, ECORE_MAGIC_EVAS);
193
194    _ecore_evas_wl_init();
195
196    ee->engine.func = (Ecore_Evas_Engine_Func *)&_ecore_wl_engine_func;
197
198    ee->driver = "wayland_egl";
199    if (disp_name) ee->name = strdup(disp_name);
200
201    if (w < 1) w = 1;
202    if (h < 1) h = 1;
203
204    ee->x = x;
205    ee->y = y;
206    ee->w = w;
207    ee->h = h;
208    ee->req.x = ee->x;
209    ee->req.y = ee->y;
210    ee->req.w = ee->w;
211    ee->req.h = ee->h;
212    ee->rotation = 0;
213    ee->prop.max.w = 32767;
214    ee->prop.max.h = 32767;
215    ee->prop.layer = 4;
216    ee->prop.request_pos = 0;
217    ee->prop.sticky = 0;
218    ee->prop.draw_frame = frame;
219    ee->alpha = EINA_FALSE;
220
221    ee->evas = evas_new();
222    evas_data_attach_set(ee->evas, ee);
223    evas_output_method_set(ee->evas, method);
224    evas_output_size_set(ee->evas, ee->w, ee->h);
225    evas_output_viewport_set(ee->evas, 0, 0, ee->w, ee->h);
226
227    /* FIXME: This needs to be set based on theme & scale */
228    if (ee->prop.draw_frame)
229      evas_output_framespace_set(ee->evas, 4, 18, 8, 22);
230
231    if (parent)
232      p = ecore_wl_window_find(parent);
233
234    /* FIXME: Get if parent is alpha, and set */
235
236    ee->engine.wl.parent = p;
237    ee->engine.wl.win = 
238      ecore_wl_window_new(p, x, y, w, h, ECORE_WL_WINDOW_BUFFER_TYPE_EGL_WINDOW);
239    ee->prop.window = ee->engine.wl.win->id;
240
241    if ((einfo = (Evas_Engine_Info_Wayland_Egl *)evas_engine_info_get(ee->evas)))
242      {
243         einfo->info.display = ecore_wl_display_get();
244         einfo->info.destination_alpha = ee->alpha;
245         einfo->info.rotation = ee->rotation;
246         einfo->info.depth = 32;
247         if (!evas_engine_info_set(ee->evas, (Evas_Engine_Info *)einfo))
248           {
249              ERR("Failed to set Evas Engine Info for '%s'", ee->driver);
250              ecore_evas_free(ee);
251              _ecore_evas_wl_shutdown();
252              ecore_wl_shutdown();
253              return NULL;
254           }
255      }
256    else 
257      {
258         ERR("Failed to get Evas Engine Info for '%s'", ee->driver);
259         ecore_evas_free(ee);
260         _ecore_evas_wl_shutdown();
261         ecore_wl_shutdown();
262         return NULL;
263      }
264
265    ecore_evas_callback_pre_free_set(ee, _ecore_evas_wl_pre_free);
266
267    if (ee->prop.draw_frame) 
268      {
269         ee->engine.wl.frame = _ecore_evas_wl_frame_add(ee->evas);
270         evas_object_is_frame_object_set(ee->engine.wl.frame, EINA_TRUE);
271         evas_object_move(ee->engine.wl.frame, 0, 0);
272      }
273
274    _ecore_evas_register(ee);
275    ecore_evas_input_event_register(ee);
276
277    ecore_event_window_register(ee->prop.window, ee, ee->evas, 
278                                (Ecore_Event_Mouse_Move_Cb)_ecore_evas_mouse_move_process, 
279                                (Ecore_Event_Multi_Move_Cb)_ecore_evas_mouse_multi_move_process, 
280                                (Ecore_Event_Multi_Down_Cb)_ecore_evas_mouse_multi_down_process, 
281                                (Ecore_Event_Multi_Up_Cb)_ecore_evas_mouse_multi_up_process);
282
283    /* evas_event_feed_mouse_in(ee->evas, (unsigned int)((unsigned long long)(ecore_time_get() * 1000.0) & 0xffffffff), NULL); */
284
285    return ee;
286 }
287
288 /* local functions */
289 static int 
290 _ecore_evas_wl_init(void)
291 {
292    LOGFN(__FILE__, __LINE__, __FUNCTION__);
293
294    if (++_ecore_evas_wl_init_count != 1)
295      return _ecore_evas_wl_init_count;
296
297    _ecore_evas_wl_event_hdls[0] = 
298      ecore_event_handler_add(ECORE_WL_EVENT_MOUSE_IN, 
299                              _ecore_evas_wl_cb_mouse_in, NULL);
300    _ecore_evas_wl_event_hdls[1] = 
301      ecore_event_handler_add(ECORE_WL_EVENT_MOUSE_OUT, 
302                              _ecore_evas_wl_cb_mouse_out, NULL);
303    _ecore_evas_wl_event_hdls[2] = 
304      ecore_event_handler_add(ECORE_WL_EVENT_FOCUS_IN, 
305                              _ecore_evas_wl_cb_focus_in, NULL);
306    _ecore_evas_wl_event_hdls[3] = 
307      ecore_event_handler_add(ECORE_WL_EVENT_FOCUS_OUT, 
308                              _ecore_evas_wl_cb_focus_out, NULL);
309    _ecore_evas_wl_event_hdls[4] = 
310      ecore_event_handler_add(ECORE_WL_EVENT_WINDOW_CONFIGURE, 
311                              _ecore_evas_wl_cb_window_configure, NULL);
312
313    ecore_event_evas_init();
314
315    return _ecore_evas_wl_init_count;
316 }
317
318 static int 
319 _ecore_evas_wl_shutdown(void)
320 {
321    unsigned int i = 0;
322
323    LOGFN(__FILE__, __LINE__, __FUNCTION__);
324
325    if (--_ecore_evas_wl_init_count != 0)
326      return _ecore_evas_wl_init_count;
327
328    for (i = 0; i < sizeof(_ecore_evas_wl_event_hdls) / sizeof(Ecore_Event_Handler *); i++)
329      {
330         if (_ecore_evas_wl_event_hdls[i])
331           ecore_event_handler_del(_ecore_evas_wl_event_hdls[i]);
332      }
333
334    ecore_event_evas_shutdown();
335
336    return _ecore_evas_wl_init_count;
337 }
338
339 static void 
340 _ecore_evas_wl_pre_free(Ecore_Evas *ee)
341 {
342    LOGFN(__FILE__, __LINE__, __FUNCTION__);
343
344    if (!ee) return;
345    if (ee->engine.wl.frame) evas_object_del(ee->engine.wl.frame);
346 }
347
348 static void 
349 _ecore_evas_wl_free(Ecore_Evas *ee)
350 {
351    LOGFN(__FILE__, __LINE__, __FUNCTION__);
352
353    if (ee->engine.wl.win) ecore_wl_window_free(ee->engine.wl.win);
354    ee->engine.wl.win = NULL;
355
356    ecore_event_window_unregister(ee->prop.window);
357    ecore_evas_input_event_unregister(ee);
358
359    _ecore_evas_wl_shutdown();
360    ecore_wl_shutdown();
361 }
362
363 static void 
364 _ecore_evas_wl_callback_resize_set(Ecore_Evas *ee, void (*func)(Ecore_Evas *ee))
365 {
366    LOGFN(__FILE__, __LINE__, __FUNCTION__);
367
368    if (!ee) return;
369    ee->func.fn_resize = func;
370 }
371
372 static void 
373 _ecore_evas_wl_callback_move_set(Ecore_Evas *ee, void (*func)(Ecore_Evas *ee))
374 {
375    LOGFN(__FILE__, __LINE__, __FUNCTION__);
376
377    if (!ee) return;
378    ee->func.fn_move = func;
379 }
380
381 static void 
382 _ecore_evas_wl_callback_delete_request_set(Ecore_Evas *ee, void (*func)(Ecore_Evas *ee))
383 {
384    LOGFN(__FILE__, __LINE__, __FUNCTION__);
385
386    if (!ee) return;
387    ee->func.fn_delete_request = func;
388 }
389
390 static void 
391 _ecore_evas_wl_callback_focus_in_set(Ecore_Evas *ee, void (*func)(Ecore_Evas *ee))
392 {
393    LOGFN(__FILE__, __LINE__, __FUNCTION__);
394
395    if (!ee) return;
396    ee->func.fn_focus_in = func;
397 }
398
399 static void 
400 _ecore_evas_wl_callback_focus_out_set(Ecore_Evas *ee, void (*func)(Ecore_Evas *ee))
401 {
402    LOGFN(__FILE__, __LINE__, __FUNCTION__);
403
404    if (!ee) return;
405    ee->func.fn_focus_out = func;
406 }
407
408 static void 
409 _ecore_evas_wl_callback_mouse_in_set(Ecore_Evas *ee, void (*func)(Ecore_Evas *ee))
410 {
411    LOGFN(__FILE__, __LINE__, __FUNCTION__);
412
413    if (!ee) return;
414    ee->func.fn_mouse_in = func;
415 }
416
417 static void 
418 _ecore_evas_wl_callback_mouse_out_set(Ecore_Evas *ee, void (*func)(Ecore_Evas *ee))
419 {
420    LOGFN(__FILE__, __LINE__, __FUNCTION__);
421
422    if (!ee) return;
423    ee->func.fn_mouse_out = func;
424 }
425
426 static void 
427 _ecore_evas_wl_move(Ecore_Evas *ee, int x, int y)
428 {
429    LOGFN(__FILE__, __LINE__, __FUNCTION__);
430
431    if (!ee) return;
432    ee->req.x = x;
433    ee->req.y = y;
434    if ((ee->x != x) || (ee->y != y))
435      {
436         ee->x = x;
437         ee->y = y;
438         if (ee->engine.wl.win) 
439           ecore_wl_window_update_location(ee->engine.wl.win, x, y);
440         if (ee->func.fn_move) ee->func.fn_move(ee);
441      }
442 }
443
444 static void 
445 _ecore_evas_wl_resize(Ecore_Evas *ee, int w, int h)
446 {
447    LOGFN(__FILE__, __LINE__, __FUNCTION__);
448
449    if (!ee) return;
450    if (w < 1) w = 1;
451    if (h < 1) h = 1;
452
453    if (ee->prop.min.w > w) w = ee->prop.min.w;
454    else if (w > ee->prop.max.w) w = ee->prop.max.w;
455    if (ee->prop.min.h > h) h = ee->prop.min.h;
456    else if (h > ee->prop.max.h) h = ee->prop.max.h;
457
458    ee->req.w = w;
459    ee->req.h = h;
460
461 //   ecore_wl_window_damage(ee->engine.wl.win, 0, 0, ee->w, ee->h);
462
463    if ((ee->w != w) || (ee->h != h))
464      {
465         ee->w = w;
466         ee->h = h;
467
468         if ((ee->rotation == 90) || (ee->rotation == 270))
469           {
470              evas_output_size_set(ee->evas, h, w);
471              evas_output_viewport_set(ee->evas, 0, 0, h, w);
472           }
473         else 
474           {
475              evas_output_size_set(ee->evas, w, h);
476              evas_output_viewport_set(ee->evas, 0, 0, w, h);
477           }
478
479         if (ee->prop.avoid_damage)
480           {
481              int pdam = 0;
482
483              pdam = ecore_evas_avoid_damage_get(ee);
484              ecore_evas_avoid_damage_set(ee, 0);
485              ecore_evas_avoid_damage_set(ee, pdam);
486           }
487
488         if (ee->engine.wl.frame)
489           evas_object_resize(ee->engine.wl.frame, ee->w, ee->h);
490
491         /* set new engine destination */
492         /* evas_engine_info_set(ee->evas, (Evas_Engine_Info *)einfo); */
493
494         /* ecore_wl_window_damage(ee->engine.wl.win, 0, 0, ee->w, ee->h); */
495
496         // WAS ACTIVE
497         /* ecore_wl_flush(); */
498
499         if (ee->engine.wl.win)
500           ecore_wl_window_update_size(ee->engine.wl.win, ee->w, ee->h);
501
502         if (ee->func.fn_resize) ee->func.fn_resize(ee);
503      }
504 }
505
506 static void 
507 _ecore_evas_wl_show(Ecore_Evas *ee)
508 {
509    Evas_Engine_Info_Wayland_Egl *einfo;
510
511    LOGFN(__FILE__, __LINE__, __FUNCTION__);
512
513    if ((!ee) || (ee->visible)) return;
514
515    if (ee->engine.wl.win)
516      {
517         ecore_wl_window_show(ee->engine.wl.win);
518         ecore_wl_window_update_size(ee->engine.wl.win, ee->w, ee->h);
519         /* ecore_wl_sync(); */
520
521         if ((ee->prop.clas) && (ee->engine.wl.win->shell_surface))
522           wl_shell_surface_set_class(ee->engine.wl.win->shell_surface, 
523                                      ee->prop.clas);
524         if ((ee->prop.title) && (ee->engine.wl.win->shell_surface))
525           wl_shell_surface_set_title(ee->engine.wl.win->shell_surface, 
526                                      ee->prop.title);
527      }
528
529    if (ee->engine.wl.frame)
530      {
531         evas_object_show(ee->engine.wl.frame);
532         evas_object_resize(ee->engine.wl.frame, ee->w, ee->h);
533      }
534
535    if (ee->engine.wl.win)
536      {
537         einfo = (Evas_Engine_Info_Wayland_Egl *)evas_engine_info_get(ee->evas);
538         if (!einfo)
539           {
540              ERR("Failed to get Evas Engine Info for '%s'", ee->driver);
541              return;
542           }
543
544         einfo->info.surface = ecore_wl_window_surface_get(ee->engine.wl.win);
545         /* if (einfo->info.surface) */
546         evas_engine_info_set(ee->evas, (Evas_Engine_Info *)einfo);
547         /* else */
548         /*   printf("Failed to get a Surface from Ecore_Wl\n"); */
549      }
550
551    /* ecore_wl_window_buffer_attach(ee->engine.wl.win, ee->engine.wl.buffer, 0, 0); */
552
553    ee->visible = 1;
554    if (ee->func.fn_show) ee->func.fn_show(ee);
555 }
556
557 static void 
558 _ecore_evas_wl_hide(Ecore_Evas *ee)
559 {
560    Evas_Engine_Info_Wayland_Egl *einfo;
561
562    LOGFN(__FILE__, __LINE__, __FUNCTION__);
563
564    if ((!ee) || (!ee->visible)) return;
565
566    einfo = (Evas_Engine_Info_Wayland_Egl *)evas_engine_info_get(ee->evas);
567    if (einfo)
568      {
569         einfo->info.surface = NULL;
570         evas_engine_info_set(ee->evas, (Evas_Engine_Info *)einfo);
571      }
572
573    if (ee->engine.wl.win) 
574      ecore_wl_window_hide(ee->engine.wl.win);
575
576    ee->visible = 0;
577    ee->should_be_visible = 0;
578
579    if (ee->func.fn_hide) ee->func.fn_hide(ee);
580 }
581
582 static void 
583 _ecore_evas_wl_raise(Ecore_Evas *ee)
584 {
585    LOGFN(__FILE__, __LINE__, __FUNCTION__);
586
587    if ((!ee) || (!ee->visible)) return;
588    ecore_wl_window_raise(ee->engine.wl.win);
589 }
590
591 static void 
592 _ecore_evas_wl_title_set(Ecore_Evas *ee, const char *title)
593 {
594    LOGFN(__FILE__, __LINE__, __FUNCTION__);
595
596    if (!ee) return;
597    if (ee->prop.title) free(ee->prop.title);
598    ee->prop.title = NULL;
599    if (title) ee->prop.title = strdup(title);
600    if ((ee->prop.draw_frame) && (ee->engine.wl.frame)) 
601      {
602         EE_Wl_Smart_Data *sd;
603
604         if (!(sd = evas_object_smart_data_get(ee->engine.wl.frame))) return;
605         evas_object_text_text_set(sd->text, ee->prop.title);
606      }
607
608    if ((ee->prop.title) && (ee->engine.wl.win->shell_surface))
609      wl_shell_surface_set_title(ee->engine.wl.win->shell_surface, 
610                                 ee->prop.title);
611 }
612
613 static void 
614 _ecore_evas_wl_name_class_set(Ecore_Evas *ee, const char *n, const char *c) 
615 {
616    LOGFN(__FILE__, __LINE__, __FUNCTION__);
617
618    if (!ee) return;
619    if (ee->prop.name) free(ee->prop.name);
620    if (ee->prop.clas) free(ee->prop.clas);
621    ee->prop.name = NULL;
622    ee->prop.clas = NULL;
623    if (n) ee->prop.name = strdup(n);
624    if (c) ee->prop.clas = strdup(c);
625
626    if ((ee->prop.clas) && (ee->engine.wl.win->shell_surface))
627      wl_shell_surface_set_class(ee->engine.wl.win->shell_surface, 
628                                 ee->prop.clas);
629 }
630
631 static void 
632 _ecore_evas_wl_size_min_set(Ecore_Evas *ee, int w, int h) 
633 {
634    LOGFN(__FILE__, __LINE__, __FUNCTION__);
635
636    if (!ee) return;
637    if (w < 0) w = 0;
638    if (h < 0) h = 0;
639    if ((ee->prop.min.w == w) && (ee->prop.min.h == h)) return;
640    ee->prop.min.w = w;
641    ee->prop.min.h = h;
642 }
643
644 static void 
645 _ecore_evas_wl_size_max_set(Ecore_Evas *ee, int w, int h) 
646 {
647    LOGFN(__FILE__, __LINE__, __FUNCTION__);
648
649    if (!ee) return;
650    if (w < 0) w = 0;
651    if (h < 0) h = 0;
652    if ((ee->prop.max.w == w) && (ee->prop.max.h == h)) return;
653    ee->prop.max.w = w;
654    ee->prop.max.h = h;
655 }
656
657 static void 
658 _ecore_evas_wl_size_base_set(Ecore_Evas *ee, int w, int h) 
659 {
660    LOGFN(__FILE__, __LINE__, __FUNCTION__);
661
662    if (!ee) return;
663    if (w < 0) w = 0;
664    if (h < 0) h = 0;
665    if ((ee->prop.base.w == w) && (ee->prop.base.h == h)) return;
666    ee->prop.base.w = w;
667    ee->prop.base.h = h;
668 }
669
670 static void 
671 _ecore_evas_wl_size_step_set(Ecore_Evas *ee, int w, int h) 
672 {
673    LOGFN(__FILE__, __LINE__, __FUNCTION__);
674
675    if (!ee) return;
676    if (w < 0) w = 0;
677    if (h < 0) h = 0;
678    if ((ee->prop.step.w == w) && (ee->prop.step.h == h)) return;
679    ee->prop.step.w = w;
680    ee->prop.step.h = h;
681 }
682
683 static void 
684 _ecore_evas_wl_layer_set(Ecore_Evas *ee, int layer)
685 {
686    LOGFN(__FILE__, __LINE__, __FUNCTION__);
687
688    if (!ee) return;
689    if (ee->prop.layer == layer) return;
690    if (layer < 1) layer = 1;
691    else if (layer > 255) layer = 255;
692    ee->prop.layer = layer;
693 }
694
695 static void 
696 _ecore_evas_wl_iconified_set(Ecore_Evas *ee, int iconify)
697 {
698    LOGFN(__FILE__, __LINE__, __FUNCTION__);
699
700    if (!ee) return;
701    if (ee->prop.iconified == iconify) return;
702    ee->prop.iconified = iconify;
703    /* FIXME: Implement this in Wayland someshow */
704 }
705
706 static void 
707 _ecore_evas_wl_maximized_set(Ecore_Evas *ee, int max)
708 {
709    LOGFN(__FILE__, __LINE__, __FUNCTION__);
710
711    if (!ee) return;
712    if (ee->prop.maximized == max) return;
713    ee->prop.maximized = max;
714    ecore_wl_window_maximized_set(ee->engine.wl.win, max);
715 }
716
717 static void 
718 _ecore_evas_wl_fullscreen_set(Ecore_Evas *ee, int full)
719 {
720    LOGFN(__FILE__, __LINE__, __FUNCTION__);
721
722    if ((!ee) || (!ee->visible)) return;
723    if (ee->prop.fullscreen == full) return;
724    ee->prop.fullscreen = full;
725    ecore_wl_window_fullscreen_set(ee->engine.wl.win, full);
726 }
727
728 static void 
729 _ecore_evas_wl_ignore_events_set(Ecore_Evas *ee, int ignore)
730 {
731    LOGFN(__FILE__, __LINE__, __FUNCTION__);
732
733    if (!ee) return;
734    ee->ignore_events = ignore;
735    /* NB: Hmmm, may need to pass this to ecore_wl_window in the future */
736 }
737
738 static void 
739 _ecore_evas_wl_alpha_set(Ecore_Evas *ee, int alpha)
740 {
741    Evas_Engine_Info_Wayland_Egl *einfo;
742
743    LOGFN(__FILE__, __LINE__, __FUNCTION__);
744
745    if (!ee) return;
746    if ((ee->alpha == alpha)) return;
747    ee->alpha = alpha;
748    if ((einfo = (Evas_Engine_Info_Wayland_Egl *)evas_engine_info_get(ee->evas)))
749      {
750         einfo->info.destination_alpha = alpha;
751         if (!evas_engine_info_set(ee->evas, (Evas_Engine_Info *)einfo))
752           ERR("evas_engine_info_set() for engine '%s' failed.", ee->driver);
753         evas_damage_rectangle_add(ee->evas, 0, 0, ee->w, ee->h);
754      }
755 }
756
757 static void 
758 _ecore_evas_wl_transparent_set(Ecore_Evas *ee, int transparent)
759 {
760    Evas_Engine_Info_Wayland_Egl *einfo;
761
762    LOGFN(__FILE__, __LINE__, __FUNCTION__);
763
764    if (!ee) return;
765    if ((ee->transparent == transparent)) return;
766    ee->transparent = transparent;
767    if (!ee->visible) return;
768    if ((einfo = (Evas_Engine_Info_Wayland_Egl *)evas_engine_info_get(ee->evas)))
769      {
770         einfo->info.destination_alpha = transparent;
771         if (!evas_engine_info_set(ee->evas, (Evas_Engine_Info *)einfo))
772           ERR("evas_engine_info_set() for engine '%s' failed.", ee->driver);
773         evas_damage_rectangle_add(ee->evas, 0, 0, ee->w, ee->h);
774      }
775 }
776
777 static int 
778 _ecore_evas_wl_render(Ecore_Evas *ee)
779 {
780    int rend = 0;
781
782    if (!ee) return 0;
783    if (!ee->visible)
784      evas_norender(ee->evas);
785    else
786      {
787         Eina_List *ll = NULL, *updates = NULL;
788         Ecore_Evas *ee2 = NULL;
789
790         if (ee->func.fn_pre_render) ee->func.fn_pre_render(ee);
791
792         EINA_LIST_FOREACH(ee->sub_ecore_evas, ll, ee2) 
793           {
794              if (ee2->func.fn_pre_render) ee2->func.fn_pre_render(ee2);
795              if (ee2->engine.func->fn_render)
796                rend |= ee2->engine.func->fn_render(ee2);
797              if (ee2->func.fn_post_render) ee2->func.fn_post_render(ee2);
798           }
799
800         if ((updates = evas_render_updates(ee->evas))) 
801           {
802              Eina_List *l = NULL;
803              Eina_Rectangle *r;
804
805              LOGFN(__FILE__, __LINE__, __FUNCTION__);
806
807              EINA_LIST_FOREACH(updates, l, r) 
808                ecore_wl_window_damage(ee->engine.wl.win, 
809                                       r->x, r->y, r->w, r->h);
810
811              ecore_wl_flush();
812
813              evas_render_updates_free(updates);
814              _ecore_evas_idle_timeout_update(ee);
815              rend = 1;
816           }
817
818         if (ee->func.fn_post_render) ee->func.fn_post_render(ee);
819      }
820    return rend;
821 }
822
823 static void 
824 _ecore_evas_wl_screen_geometry_get(const Ecore_Evas *ee __UNUSED__, int *x, int *y, int *w, int *h)
825 {
826    LOGFN(__FILE__, __LINE__, __FUNCTION__);
827
828    if (x) *x = 0;
829    if (y) *y = 0;
830    ecore_wl_screen_size_get(w, h);
831 }
832
833 void 
834 _ecore_evas_wayland_egl_resize(Ecore_Evas *ee, int location)
835 {
836    LOGFN(__FILE__, __LINE__, __FUNCTION__);
837
838    if (!ee) return;
839    if (ee->engine.wl.win) 
840      {
841         ee->engine.wl.win->resizing = EINA_TRUE;
842         ecore_wl_window_resize(ee->engine.wl.win, ee->w, ee->h, location);
843      }
844 }
845
846 void 
847 _ecore_evas_wayland_egl_move(Ecore_Evas *ee, int x, int y)
848 {
849    LOGFN(__FILE__, __LINE__, __FUNCTION__);
850
851    if (!ee) return;
852    if (ee->engine.wl.win) 
853      {
854         ee->engine.wl.win->moving = EINA_TRUE;
855         ecore_wl_window_move(ee->engine.wl.win, x, y);
856      }
857 }
858
859 static Eina_Bool 
860 _ecore_evas_wl_cb_mouse_in(void *data __UNUSED__, int type __UNUSED__, void *event)
861 {
862    Ecore_Evas *ee;
863    Ecore_Wl_Event_Mouse_In *ev;
864
865    LOGFN(__FILE__, __LINE__, __FUNCTION__);
866
867    ev = event;
868    ee = ecore_event_window_match(ev->window);
869    if ((!ee) || (ee->ignore_events)) return ECORE_CALLBACK_PASS_ON;
870    if (ev->window != ee->prop.window) return ECORE_CALLBACK_PASS_ON;
871    if (ee->func.fn_mouse_in) ee->func.fn_mouse_in(ee);
872    ecore_event_evas_modifier_lock_update(ee->evas, ev->modifiers);
873    evas_event_feed_mouse_in(ee->evas, ev->timestamp, NULL);
874    _ecore_evas_mouse_move_process(ee, ev->x, ev->y, ev->timestamp);
875    return ECORE_CALLBACK_PASS_ON;
876 }
877
878 static Eina_Bool 
879 _ecore_evas_wl_cb_mouse_out(void *data __UNUSED__, int type __UNUSED__, void *event)
880 {
881    Ecore_Evas *ee;
882    Ecore_Wl_Event_Mouse_Out *ev;
883
884    LOGFN(__FILE__, __LINE__, __FUNCTION__);
885
886    ev = event;
887    ee = ecore_event_window_match(ev->window);
888    if ((!ee) || (ee->ignore_events)) return ECORE_CALLBACK_PASS_ON;
889    if (ev->window != ee->prop.window) return ECORE_CALLBACK_PASS_ON;
890    ecore_event_evas_modifier_lock_update(ee->evas, ev->modifiers);
891    _ecore_evas_mouse_move_process(ee, ev->x, ev->y, ev->timestamp);
892    evas_event_feed_mouse_out(ee->evas, ev->timestamp, NULL);
893    if (ee->func.fn_mouse_out) ee->func.fn_mouse_out(ee);
894    if (ee->prop.cursor.object) evas_object_hide(ee->prop.cursor.object);
895    return ECORE_CALLBACK_PASS_ON;
896 }
897
898 static Eina_Bool 
899 _ecore_evas_wl_cb_focus_in(void *data __UNUSED__, int type __UNUSED__, void *event)
900 {
901    Ecore_Evas *ee;
902    Ecore_Wl_Event_Focus_In *ev;
903
904    LOGFN(__FILE__, __LINE__, __FUNCTION__);
905
906    ev = event;
907    ee = ecore_event_window_match(ev->win);
908    if ((!ee) || (ee->ignore_events)) return ECORE_CALLBACK_PASS_ON;
909    if (ev->win != ee->prop.window) return ECORE_CALLBACK_PASS_ON;
910    ee->prop.focused = 1;
911    evas_focus_in(ee->evas);
912    if (ee->func.fn_focus_in) ee->func.fn_focus_in(ee);
913    return ECORE_CALLBACK_PASS_ON;
914 }
915
916 static Eina_Bool 
917 _ecore_evas_wl_cb_focus_out(void *data __UNUSED__, int type __UNUSED__, void *event)
918 {
919    Ecore_Evas *ee;
920    Ecore_Wl_Event_Focus_In *ev;
921
922    LOGFN(__FILE__, __LINE__, __FUNCTION__);
923
924    ev = event;
925    ee = ecore_event_window_match(ev->win);
926    if ((!ee) || (ee->ignore_events)) return ECORE_CALLBACK_PASS_ON;
927    if (ev->win != ee->prop.window) return ECORE_CALLBACK_PASS_ON;
928    evas_focus_out(ee->evas);
929    ee->prop.focused = 0;
930    if (ee->func.fn_focus_out) ee->func.fn_focus_out(ee);
931    return ECORE_CALLBACK_PASS_ON;
932 }
933
934 static Eina_Bool 
935 _ecore_evas_wl_cb_window_configure(void *data __UNUSED__, int type __UNUSED__, void *event)
936 {
937    Ecore_Evas *ee;
938    Ecore_Wl_Event_Window_Configure *ev;
939
940    LOGFN(__FILE__, __LINE__, __FUNCTION__);
941
942    ev = event;
943    ee = ecore_event_window_match(ev->win);
944    if (!ee) return ECORE_CALLBACK_PASS_ON;
945    if (ev->win != ee->prop.window) return ECORE_CALLBACK_PASS_ON;
946    if ((ee->x != ev->x) || (ee->y != ev->y))
947      {
948         ee->x = ev->x;
949         ee->y = ev->y;
950         ee->req.x = ee->x;
951         ee->req.y = ee->y;
952         if (ee->func.fn_move) ee->func.fn_move(ee);
953      }
954    if ((ee->req.w != ev->w) || (ee->req.h != ev->h))
955      {
956         ee->req.w = ev->w;
957         ee->req.h = ev->h;
958         if (ee->func.fn_resize) ee->func.fn_resize(ee);
959      }
960
961    return ECORE_CALLBACK_PASS_ON;
962 }
963
964 static void 
965 _ecore_evas_wl_smart_init(void) 
966 {
967    if (_ecore_evas_wl_smart) return;
968      {
969         static const Evas_Smart_Class sc = 
970           {
971              "ecore_evas_wl_frame", EVAS_SMART_CLASS_VERSION, 
972              _ecore_evas_wl_smart_add, 
973              _ecore_evas_wl_smart_del, 
974              NULL, 
975              _ecore_evas_wl_smart_resize, 
976              _ecore_evas_wl_smart_show, 
977              _ecore_evas_wl_smart_hide, 
978              NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
979           };
980         _ecore_evas_wl_smart = evas_smart_class_new(&sc);
981      }
982 }
983
984 static void 
985 _ecore_evas_wl_smart_add(Evas_Object *obj) 
986 {
987    EE_Wl_Smart_Data *sd;
988    Evas *evas;
989
990    LOGFN(__FILE__, __LINE__, __FUNCTION__);
991
992    if (!(sd = calloc(1, sizeof(EE_Wl_Smart_Data)))) return;
993
994    evas = evas_object_evas_get(obj);
995
996    sd->x = 0;
997    sd->y = 0;
998    sd->w = 1;
999    sd->h = 1;
1000
1001    sd->frame = evas_object_rectangle_add(evas);
1002    evas_object_is_frame_object_set(sd->frame, EINA_TRUE);
1003    evas_object_color_set(sd->frame, 249, 249, 249, 255);
1004    evas_object_smart_member_add(sd->frame, obj);
1005
1006    sd->text = evas_object_text_add(evas);
1007    evas_object_color_set(sd->text, 0, 0, 0, 255);
1008    evas_object_text_style_set(sd->text, EVAS_TEXT_STYLE_PLAIN);
1009    evas_object_text_font_set(sd->text, "Sans", 10);
1010    evas_object_text_text_set(sd->text, "Smart Test");
1011
1012    evas_object_smart_data_set(obj, sd);
1013 }
1014
1015 static void 
1016 _ecore_evas_wl_smart_del(Evas_Object *obj) 
1017 {
1018    EE_Wl_Smart_Data *sd;
1019
1020    LOGFN(__FILE__, __LINE__, __FUNCTION__);
1021
1022    if (!(sd = evas_object_smart_data_get(obj))) return;
1023    evas_object_del(sd->text);
1024    evas_object_del(sd->frame);
1025    free(sd);
1026 }
1027
1028 static void 
1029 _ecore_evas_wl_smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h) 
1030 {
1031    EE_Wl_Smart_Data *sd;
1032
1033    LOGFN(__FILE__, __LINE__, __FUNCTION__);
1034
1035    if (!(sd = evas_object_smart_data_get(obj))) return;
1036    if ((sd->w == w) && (sd->h == h)) return;
1037    sd->w = w;
1038    sd->h = h;
1039    evas_object_resize(sd->frame, w, h);
1040 }
1041
1042 static void 
1043 _ecore_evas_wl_smart_show(Evas_Object *obj) 
1044 {
1045    EE_Wl_Smart_Data *sd;
1046
1047    LOGFN(__FILE__, __LINE__, __FUNCTION__);
1048
1049    if (!(sd = evas_object_smart_data_get(obj))) return;
1050    evas_object_show(sd->frame);
1051    evas_object_show(sd->text);
1052 }
1053
1054 static void 
1055 _ecore_evas_wl_smart_hide(Evas_Object *obj) 
1056 {
1057    EE_Wl_Smart_Data *sd;
1058
1059    LOGFN(__FILE__, __LINE__, __FUNCTION__);
1060
1061    if (!(sd = evas_object_smart_data_get(obj))) return;
1062    evas_object_hide(sd->text);
1063    evas_object_hide(sd->frame);
1064 }
1065
1066 static Evas_Object *
1067 _ecore_evas_wl_frame_add(Evas *evas) 
1068 {
1069    LOGFN(__FILE__, __LINE__, __FUNCTION__);
1070
1071    _ecore_evas_wl_smart_init();
1072    return evas_object_smart_add(evas, _ecore_evas_wl_smart);
1073 }
1074
1075 #else
1076 EAPI Ecore_Evas *
1077 ecore_evas_wayland_egl_new(const char *disp_name __UNUSED__, unsigned int parent __UNUSED__, int x __UNUSED__, int y __UNUSED__, int w __UNUSED__, int h __UNUSED__, Eina_Bool frame __UNUSED__)
1078 {
1079    return NULL;
1080 }
1081 #endif