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