9 # define LOGFN(fl, ln, fn) \
10 printf("-ECORE_EVAS-WL: %25s: %5i - %s\n", fl, ln, fn);
12 # define LOGFN(fl, ln, fn)
15 #ifdef BUILD_ECORE_EVAS_WAYLAND_SHM
19 # include <sys/types.h>
20 # include <sys/mman.h>
27 # include "ecore_evas_private.h"
28 # include "Ecore_Evas.h"
30 #ifdef BUILD_ECORE_EVAS_WAYLAND_SHM
31 # include <Evas_Engine_Wayland_Shm.h>
32 # include <Ecore_Wayland.h>
34 /* local structures */
35 typedef struct _EE_Wl_Smart_Data EE_Wl_Smart_Data;
36 struct _EE_Wl_Smart_Data
40 Evas_Coord x, y, w, h;
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_move(Ecore_Evas *ee, int x, int y);
55 static void _ecore_evas_wl_resize(Ecore_Evas *ee, int w, int h);
56 static void _ecore_evas_wl_show(Ecore_Evas *ee);
57 static void _ecore_evas_wl_hide(Ecore_Evas *ee);
58 static void _ecore_evas_wl_raise(Ecore_Evas *ee);
59 static void _ecore_evas_wl_lower(Ecore_Evas *ee);
60 static void _ecore_evas_wl_activate(Ecore_Evas *ee);
61 static void _ecore_evas_wl_title_set(Ecore_Evas *ee, const char *t);
62 static void _ecore_evas_wl_name_class_set(Ecore_Evas *ee, const char *n, const char *c);
63 static void _ecore_evas_wl_size_min_set(Ecore_Evas *ee, int w, int h);
64 static void _ecore_evas_wl_size_max_set(Ecore_Evas *ee, int w, int h);
65 static void _ecore_evas_wl_size_base_set(Ecore_Evas *ee, int w, int h);
66 static void _ecore_evas_wl_size_step_set(Ecore_Evas *ee, int w, int h);
67 static void _ecore_evas_wl_object_cursor_set(Ecore_Evas *ee, Evas_Object *obj, int layer, int hot_x, int hot_y);
68 static void _ecore_evas_wl_object_cursor_del(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event __UNUSED__);
69 static void _ecore_evas_wl_layer_set(Ecore_Evas *ee, int layer);
70 static void _ecore_evas_wl_focus_set(Ecore_Evas *ee, int focus __UNUSED__);
71 static void _ecore_evas_wl_iconified_set(Ecore_Evas *ee, int iconify);
72 static void _ecore_evas_wl_maximized_set(Ecore_Evas *ee, int max);
73 static void _ecore_evas_wl_fullscreen_set(Ecore_Evas *ee, int full __UNUSED__);
74 static int _ecore_evas_wl_render(Ecore_Evas *ee);
75 static void _ecore_evas_wl_screen_geometry_get(const Ecore_Evas *ee __UNUSED__, int *x, int *y, int *w, int *h);
76 static void _ecore_evas_wl_buffer_new(Ecore_Evas *ee, void **dest);
78 static Eina_Bool _ecore_evas_wl_event_mouse_in(void *data __UNUSED__, int type __UNUSED__, void *event);
79 static Eina_Bool _ecore_evas_wl_event_mouse_out(void *data __UNUSED__, int type __UNUSED__, void *event);
80 static Eina_Bool _ecore_evas_wl_event_focus_in(void *data __UNUSED__, int type __UNUSED__, void *event);
81 static Eina_Bool _ecore_evas_wl_event_focus_out(void *data __UNUSED__, int type __UNUSED__, void *event);
83 static void _ecore_evas_wl_handle_configure(void *data, struct wl_shell_surface *shell_surface __UNUSED__, uint32_t timestamp __UNUSED__, uint32_t edges __UNUSED__, int32_t width, int32_t height);
84 static void _ecore_evas_wl_handle_popup_done(void *data __UNUSED__, struct wl_shell_surface *shell_surface __UNUSED__);
86 /* SMART stuff for frame */
87 static Evas_Smart *_ecore_evas_wl_smart = NULL;
89 static void _ecore_evas_wl_smart_init(void);
90 static void _ecore_evas_wl_smart_add(Evas_Object *obj);
91 static void _ecore_evas_wl_smart_del(Evas_Object *obj);
92 static void _ecore_evas_wl_smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h);
93 static void _ecore_evas_wl_smart_show(Evas_Object *obj);
94 static void _ecore_evas_wl_smart_hide(Evas_Object *obj);
96 static Evas_Object *_ecore_evas_wl_frame_add(Evas *evas);
99 static int _ecore_evas_wl_init_count = 0;
100 static Ecore_Event_Handler *_ecore_evas_wl_event_handlers[4];
102 static const struct wl_shell_surface_listener _ecore_evas_wl_shell_surface_listener =
104 _ecore_evas_wl_handle_configure,
105 _ecore_evas_wl_handle_popup_done
108 static Ecore_Evas_Engine_Func _ecore_wl_engine_func =
111 _ecore_evas_wl_callback_resize_set,
112 _ecore_evas_wl_callback_move_set,
113 NULL, // callback show set
114 NULL, // callback hide set
115 _ecore_evas_wl_callback_delete_request_set,
116 NULL, // callback destroy set
117 _ecore_evas_wl_callback_focus_in_set,
118 _ecore_evas_wl_callback_focus_out_set,
119 _ecore_evas_wl_callback_mouse_in_set,
120 NULL, // callback mouse out set
121 NULL, // callback sticky set
122 NULL, // callback unsticky set
123 NULL, // callback pre render set
124 NULL, // callback post render set
126 NULL, // func managed move
127 _ecore_evas_wl_resize,
128 NULL, // func move_resize
129 NULL, // func rotation set
130 NULL, // func shaped set
133 _ecore_evas_wl_raise,
134 _ecore_evas_wl_lower,
135 _ecore_evas_wl_activate,
136 _ecore_evas_wl_title_set,
137 _ecore_evas_wl_name_class_set,
138 _ecore_evas_wl_size_min_set,
139 _ecore_evas_wl_size_max_set,
140 _ecore_evas_wl_size_base_set,
141 _ecore_evas_wl_size_step_set,
142 _ecore_evas_wl_object_cursor_set,
143 _ecore_evas_wl_layer_set,
144 _ecore_evas_wl_focus_set,
145 _ecore_evas_wl_iconified_set,
146 NULL, // func borderless set
147 NULL, // func override set
148 _ecore_evas_wl_maximized_set,
149 _ecore_evas_wl_fullscreen_set,
150 NULL, // func avoid_damage set
151 NULL, // func withdrawn set
152 NULL, // func sticky set
153 NULL, // func ignore_events set
154 NULL, // func alpha set
155 NULL, // func transparent set
156 _ecore_evas_wl_render,
157 _ecore_evas_wl_screen_geometry_get
160 /* external variables */
163 #ifdef BUILD_ECORE_EVAS_WAYLAND_SHM
165 ecore_evas_wayland_shm_new(const char *disp_name, int x, int y, int w, int h, int frame)
167 Evas_Engine_Info_Wayland_Shm *einfo;
170 static int _win_id = 1;
172 LOGFN(__FILE__, __LINE__, __FUNCTION__);
174 if (!(method = evas_render_method_lookup("wayland_shm")))
176 ERR("Render method lookup failed.");
180 if (!(ecore_wl_init(disp_name)))
182 ERR("Failed to initialize Ecore Wayland.");
186 if (!(ee = calloc(1, sizeof(Ecore_Evas))))
188 ERR("Failed to allocate Ecore_Evas.");
193 ECORE_MAGIC_SET(ee, ECORE_MAGIC_EVAS);
195 _ecore_evas_wl_init();
197 ee->engine.func = (Ecore_Evas_Engine_Func *)&_ecore_wl_engine_func;
199 ee->driver = "wayland_shm";
200 if (disp_name) ee->name = strdup(disp_name);
205 ee->req.x = ee->x = x;
206 ee->req.y = ee->y = y;
207 ee->req.w = ee->w = w;
208 ee->req.h = ee->h = h;
210 ee->prop.max.w = ee->prop.max.h = 32767;
212 ee->prop.request_pos = 0;
214 ee->prop.draw_frame = frame;
215 ee->prop.window = _win_id++;
217 ee->evas = evas_new();
218 evas_data_attach_set(ee->evas, ee);
219 evas_output_method_set(ee->evas, method);
220 evas_output_size_set(ee->evas, ee->w, ee->h);
221 evas_output_viewport_set(ee->evas, 0, 0, ee->w, ee->h);
223 if (ee->prop.draw_frame)
224 evas_output_framespace_set(ee->evas, 4, 18, 8, 22);
226 if ((einfo = (Evas_Engine_Info_Wayland_Shm *)evas_engine_info_get(ee->evas)))
228 einfo->info.rotation = ee->rotation;
229 einfo->info.debug = EINA_FALSE;
230 if (!evas_engine_info_set(ee->evas, (Evas_Engine_Info *)einfo))
232 ERR("Failed to set Evas Engine Info for '%s'.", ee->driver);
239 ERR("Failed to get Evas Engine Info for '%s'.", ee->driver);
244 /* NB: we need to be notified before 'free' so we can munmap the evas
245 * engine destination */
246 ecore_evas_callback_pre_free_set(ee, _ecore_evas_wl_pre_free);
248 if (ee->prop.draw_frame)
250 ee->engine.wl.frame = _ecore_evas_wl_frame_add(ee->evas);
251 evas_object_is_frame_object_set(ee->engine.wl.frame, EINA_TRUE);
252 evas_object_move(ee->engine.wl.frame, 0, 0);
255 ecore_evas_input_event_register(ee);
256 _ecore_evas_register(ee);
258 ecore_event_window_register(ee->prop.window, ee, ee->evas,
259 (Ecore_Event_Mouse_Move_Cb)_ecore_evas_mouse_move_process,
260 (Ecore_Event_Multi_Move_Cb)_ecore_evas_mouse_multi_move_process,
261 (Ecore_Event_Multi_Down_Cb)_ecore_evas_mouse_multi_down_process,
262 (Ecore_Event_Multi_Up_Cb)_ecore_evas_mouse_multi_up_process);
264 evas_event_feed_mouse_in(ee->evas, (unsigned int)((unsigned long long)(ecore_time_get() * 1000.0) & 0xffffffff), NULL);
269 /* local functions */
271 _ecore_evas_wl_init(void)
273 LOGFN(__FILE__, __LINE__, __FUNCTION__);
275 if (++_ecore_evas_wl_init_count != 1)
276 return _ecore_evas_wl_init_count;
278 _ecore_evas_wl_event_handlers[0] =
279 ecore_event_handler_add(ECORE_WL_EVENT_MOUSE_IN,
280 _ecore_evas_wl_event_mouse_in, NULL);
281 _ecore_evas_wl_event_handlers[1] =
282 ecore_event_handler_add(ECORE_WL_EVENT_MOUSE_OUT,
283 _ecore_evas_wl_event_mouse_out, NULL);
284 _ecore_evas_wl_event_handlers[2] =
285 ecore_event_handler_add(ECORE_WL_EVENT_FOCUS_IN,
286 _ecore_evas_wl_event_focus_in, NULL);
287 _ecore_evas_wl_event_handlers[3] =
288 ecore_event_handler_add(ECORE_WL_EVENT_FOCUS_OUT,
289 _ecore_evas_wl_event_focus_out, NULL);
291 ecore_event_evas_init();
293 return _ecore_evas_wl_init_count;
297 _ecore_evas_wl_shutdown(void)
301 LOGFN(__FILE__, __LINE__, __FUNCTION__);
303 if (--_ecore_evas_wl_init_count != 0)
304 return _ecore_evas_wl_init_count;
306 for (i = 0; i < sizeof(_ecore_evas_wl_event_handlers) / sizeof(Ecore_Event_Handler *); i++)
308 if (_ecore_evas_wl_event_handlers[i])
309 ecore_event_handler_del(_ecore_evas_wl_event_handlers[i]);
312 ecore_event_evas_shutdown();
314 return _ecore_evas_wl_init_count;
318 _ecore_evas_wl_pre_free(Ecore_Evas *ee)
320 Evas_Engine_Info_Wayland_Shm *einfo;
322 LOGFN(__FILE__, __LINE__, __FUNCTION__);
325 if (ee->engine.wl.frame) evas_object_del(ee->engine.wl.frame);
327 /* get engine info */
328 einfo = (Evas_Engine_Info_Wayland_Shm *)evas_engine_info_get(ee->evas);
329 if ((einfo) && (einfo->info.dest))
333 /* munmap previous engine destination */
334 ret = munmap(einfo->info.dest, ((ee->w * sizeof(int)) * ee->h));
339 _ecore_evas_wl_free(Ecore_Evas *ee)
341 LOGFN(__FILE__, __LINE__, __FUNCTION__);
344 if (ee->engine.wl.buffer) wl_buffer_destroy(ee->engine.wl.buffer);
345 ee->engine.wl.buffer = NULL;
347 /* destroy shell surface */
348 if (ee->engine.wl.shell_surface)
349 wl_shell_surface_destroy(ee->engine.wl.shell_surface);
350 ee->engine.wl.shell_surface = NULL;
352 /* destroy surface */
353 if (ee->engine.wl.surface) wl_surface_destroy(ee->engine.wl.surface);
354 ee->engine.wl.surface = NULL;
356 ecore_event_window_unregister(ee->prop.window);
357 ecore_evas_input_event_unregister(ee);
359 _ecore_evas_wl_shutdown();
364 _ecore_evas_wl_callback_resize_set(Ecore_Evas *ee, void (*func)(Ecore_Evas *ee))
366 LOGFN(__FILE__, __LINE__, __FUNCTION__);
369 ee->func.fn_resize = func;
373 _ecore_evas_wl_callback_move_set(Ecore_Evas *ee, void (*func)(Ecore_Evas *ee))
375 LOGFN(__FILE__, __LINE__, __FUNCTION__);
378 ee->func.fn_move = func;
382 _ecore_evas_wl_callback_delete_request_set(Ecore_Evas *ee, void (*func)(Ecore_Evas *ee))
384 LOGFN(__FILE__, __LINE__, __FUNCTION__);
387 ee->func.fn_delete_request = func;
391 _ecore_evas_wl_callback_focus_in_set(Ecore_Evas *ee, void (*func)(Ecore_Evas *ee))
393 LOGFN(__FILE__, __LINE__, __FUNCTION__);
396 ee->func.fn_focus_in = func;
400 _ecore_evas_wl_callback_focus_out_set(Ecore_Evas *ee, void (*func)(Ecore_Evas *ee))
402 LOGFN(__FILE__, __LINE__, __FUNCTION__);
405 ee->func.fn_focus_out = func;
409 _ecore_evas_wl_callback_mouse_in_set(Ecore_Evas *ee, void (*func)(Ecore_Evas *ee))
411 LOGFN(__FILE__, __LINE__, __FUNCTION__);
414 ee->func.fn_mouse_in = func;
418 _ecore_evas_wl_move(Ecore_Evas *ee, int x, int y)
420 LOGFN(__FILE__, __LINE__, __FUNCTION__);
423 // if ((ee->x == x) && (ee->y == y)) return;
430 if (ee->engine.wl.shell_surface)
432 wl_shell_surface_move(ee->engine.wl.shell_surface,
433 ecore_wl_input_device_get(),
434 ecore_wl_input_timestamp_get());
437 if (ee->func.fn_move) ee->func.fn_move(ee);
441 _ecore_evas_wl_resize(Ecore_Evas *ee, int w, int h)
443 Evas_Engine_Info_Wayland_Shm *einfo;
445 LOGFN(__FILE__, __LINE__, __FUNCTION__);
450 if ((ee->w == w) && (ee->h == h)) return;
452 if (ee->prop.min.w > w) w = ee->prop.min.w;
453 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;
463 /* damage old surface, if it exists */
465 /* NB: This removes any lingering screen artifacts in the compositor.
466 * This may be a 'HACK' if the issue is actually in the wayland
467 * compositor, but for now lets implement this so we don't have screen
468 * artifacts laying around during a resize */
469 if (ee->engine.wl.surface)
470 wl_surface_damage(ee->engine.wl.surface, 0, 0, ee->w, ee->h);
473 /* get engine info */
474 einfo = (Evas_Engine_Info_Wayland_Shm *)evas_engine_info_get(ee->evas);
475 if (einfo->info.dest)
479 /* munmap previous engine destination */
480 ret = munmap(einfo->info.dest, ((ee->w * sizeof(int)) * ee->h));
483 /* free old buffer */
484 if (ee->engine.wl.buffer) wl_buffer_destroy(ee->engine.wl.buffer);
485 ee->engine.wl.buffer = NULL;
490 /* create buffer @ new size (also mmaps the new destination) */
491 _ecore_evas_wl_buffer_new(ee, &einfo->info.dest);
493 /* flush new buffer fd */
496 /* change evas output & viewport sizes */
497 evas_output_size_set(ee->evas, ee->w, ee->h);
498 evas_output_viewport_set(ee->evas, 0, 0, ee->w, ee->h);
499 evas_damage_rectangle_add(ee->evas, 0, 0, ee->w, ee->h);
500 if (ee->engine.wl.frame)
501 evas_object_resize(ee->engine.wl.frame, ee->w, ee->h);
503 /* set new engine destination */
504 evas_engine_info_set(ee->evas, (Evas_Engine_Info *)einfo);
507 wl_buffer_damage(ee->engine.wl.buffer, 0, 0, ee->w, ee->h);
512 wl_surface_damage(ee->engine.wl.surface, 0, 0, ee->w, ee->h);
514 /* if visible, attach to surface */
515 wl_surface_attach(ee->engine.wl.surface, ee->engine.wl.buffer, 0, 0);
518 if (ee->func.fn_resize) ee->func.fn_resize(ee);
522 _ecore_evas_wl_show(Ecore_Evas *ee)
524 Evas_Engine_Info_Wayland_Shm *einfo;
526 LOGFN(__FILE__, __LINE__, __FUNCTION__);
529 if (ee->visible) return;
531 /* get engine info */
532 einfo = (Evas_Engine_Info_Wayland_Shm *)evas_engine_info_get(ee->evas);
534 /* create new surface */
535 ee->engine.wl.surface =
536 wl_compositor_create_surface(ecore_wl_compositor_get());
537 wl_surface_set_user_data(ee->engine.wl.surface, (void *)ee->prop.window);
539 /* get new shell surface */
540 ee->engine.wl.shell_surface =
541 wl_shell_get_shell_surface(ecore_wl_shell_get(), ee->engine.wl.surface);
544 wl_shell_surface_set_toplevel(ee->engine.wl.shell_surface);
546 /* create buffer @ new size (also mmaps the new destination) */
547 _ecore_evas_wl_buffer_new(ee, &einfo->info.dest);
549 if (ee->engine.wl.frame)
551 evas_object_show(ee->engine.wl.frame);
552 evas_object_resize(ee->engine.wl.frame, ee->w, ee->h);
555 /* set new engine destination */
556 evas_engine_info_set(ee->evas, (Evas_Engine_Info *)einfo);
558 /* add configure listener for wayland resize events */
559 wl_shell_surface_add_listener(ee->engine.wl.shell_surface,
560 &_ecore_evas_wl_shell_surface_listener, ee);
562 /* flush new buffer fd */
565 /* attach buffer to surface */
566 wl_surface_attach(ee->engine.wl.surface, ee->engine.wl.buffer, 0, 0);
568 /* NB: No need to do a damage here. If we do, we end up w/ screen
569 * artifacts in the compositor */
570 /* wl_surface_damage(ee->engine.wl.surface, 0, 0, ee->w, ee->h); */
573 if (ee->func.fn_show) ee->func.fn_show(ee);
577 _ecore_evas_wl_hide(Ecore_Evas *ee)
579 Evas_Engine_Info_Wayland_Shm *einfo;
581 LOGFN(__FILE__, __LINE__, __FUNCTION__);
584 if (!ee->visible) return;
586 /* get engine info */
587 einfo = (Evas_Engine_Info_Wayland_Shm *)evas_engine_info_get(ee->evas);
588 if (einfo->info.dest)
592 /* munmap previous engine destination */
593 ret = munmap(einfo->info.dest, ((ee->w * sizeof(int)) * ee->h));
594 einfo->info.dest = NULL;
597 /* free old buffer */
598 if (ee->engine.wl.buffer) wl_buffer_destroy(ee->engine.wl.buffer);
599 ee->engine.wl.buffer = NULL;
601 /* set new engine destination */
602 evas_engine_info_set(ee->evas, (Evas_Engine_Info *)einfo);
604 /* destroy shell surface */
605 if (ee->engine.wl.shell_surface)
606 wl_shell_surface_destroy(ee->engine.wl.shell_surface);
607 ee->engine.wl.shell_surface = NULL;
609 /* destroy surface */
610 if (ee->engine.wl.surface) wl_surface_destroy(ee->engine.wl.surface);
611 ee->engine.wl.surface = NULL;
614 ee->should_be_visible = 0;
615 if (ee->func.fn_hide) ee->func.fn_hide(ee);
619 _ecore_evas_wl_raise(Ecore_Evas *ee)
621 LOGFN(__FILE__, __LINE__, __FUNCTION__);
623 if ((!ee) || (!ee->visible)) return;
624 if (!ee->engine.wl.shell_surface) return;
625 wl_shell_surface_set_toplevel(ee->engine.wl.shell_surface);
629 _ecore_evas_wl_lower(Ecore_Evas *ee)
631 LOGFN(__FILE__, __LINE__, __FUNCTION__);
633 if ((!ee) || (!ee->visible)) return;
634 /* FIXME: Need a way to tell Wayland to lower */
638 _ecore_evas_wl_activate(Ecore_Evas *ee)
640 LOGFN(__FILE__, __LINE__, __FUNCTION__);
642 if ((!ee) || (!ee->visible)) return;
643 if (!ee->engine.wl.shell_surface) return;
644 wl_shell_surface_set_toplevel(ee->engine.wl.shell_surface);
648 _ecore_evas_wl_title_set(Ecore_Evas *ee, const char *t)
650 LOGFN(__FILE__, __LINE__, __FUNCTION__);
653 if (ee->prop.title) free(ee->prop.title);
654 ee->prop.title = NULL;
655 if (t) ee->prop.title = strdup(t);
657 if ((ee->prop.draw_frame) && (ee->engine.wl.frame))
659 EE_Wl_Smart_Data *sd;
661 if (!(sd = evas_object_smart_data_get(ee->engine.wl.frame))) return;
662 evas_object_text_text_set(sd->text, ee->prop.title);
667 _ecore_evas_wl_name_class_set(Ecore_Evas *ee, const char *n, const char *c)
669 LOGFN(__FILE__, __LINE__, __FUNCTION__);
672 if (ee->prop.name) free(ee->prop.name);
673 if (ee->prop.clas) free(ee->prop.clas);
674 ee->prop.name = NULL;
675 ee->prop.clas = NULL;
676 if (n) ee->prop.name = strdup(n);
677 if (c) ee->prop.clas = strdup(c);
678 /* FIXME: Forward these changes to Wayland somehow */
682 _ecore_evas_wl_size_min_set(Ecore_Evas *ee, int w, int h)
684 LOGFN(__FILE__, __LINE__, __FUNCTION__);
689 if ((ee->prop.min.w == w) && (ee->prop.min.h == h)) return;
695 _ecore_evas_wl_size_max_set(Ecore_Evas *ee, int w, int h)
697 LOGFN(__FILE__, __LINE__, __FUNCTION__);
702 if ((ee->prop.max.w == w) && (ee->prop.max.h == h)) return;
708 _ecore_evas_wl_size_base_set(Ecore_Evas *ee, int w, int h)
710 LOGFN(__FILE__, __LINE__, __FUNCTION__);
715 if ((ee->prop.base.w == w) && (ee->prop.base.h == h)) return;
721 _ecore_evas_wl_size_step_set(Ecore_Evas *ee, int w, int h)
723 LOGFN(__FILE__, __LINE__, __FUNCTION__);
728 if ((ee->prop.step.w == w) && (ee->prop.step.h == h)) return;
734 _ecore_evas_wl_object_cursor_set(Ecore_Evas *ee, Evas_Object *obj, int layer, int hot_x, int hot_y)
738 LOGFN(__FILE__, __LINE__, __FUNCTION__);
741 if (ee->prop.cursor.object) evas_object_del(ee->prop.cursor.object);
742 ee->prop.cursor.object = NULL;
746 ee->prop.cursor.layer = 0;
747 ee->prop.cursor.hot.x = 0;
748 ee->prop.cursor.hot.y = 0;
752 ee->prop.cursor.object = obj;
753 ee->prop.cursor.layer = layer;
754 ee->prop.cursor.hot.x = hot_x;
755 ee->prop.cursor.hot.y = hot_y;
757 evas_pointer_output_xy_get(ee->evas, &x, &y);
758 evas_object_layer_set(ee->prop.cursor.object, ee->prop.cursor.layer);
759 evas_object_move(ee->prop.cursor.object,
760 x - ee->prop.cursor.hot.x, y - ee->prop.cursor.hot.y);
761 evas_object_pass_events_set(ee->prop.cursor.object, 1);
762 if (evas_pointer_inside_get(ee->evas))
763 evas_object_show(ee->prop.cursor.object);
765 evas_object_event_callback_add(obj, EVAS_CALLBACK_DEL,
766 _ecore_evas_wl_object_cursor_del, ee);
770 _ecore_evas_wl_object_cursor_del(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event __UNUSED__)
774 if (!(ee = data)) return;
775 ee->prop.cursor.object = NULL;
779 _ecore_evas_wl_layer_set(Ecore_Evas *ee, int layer)
781 LOGFN(__FILE__, __LINE__, __FUNCTION__);
784 if (ee->prop.layer == layer) return;
785 if (layer < 1) layer = 1;
786 else if (layer > 255) layer = 255;
787 ee->prop.layer = layer;
791 _ecore_evas_wl_focus_set(Ecore_Evas *ee, int focus __UNUSED__)
793 LOGFN(__FILE__, __LINE__, __FUNCTION__);
795 if ((!ee) || (!ee->visible)) return;
796 if (!ee->engine.wl.shell_surface) return;
797 wl_shell_surface_set_toplevel(ee->engine.wl.shell_surface);
801 _ecore_evas_wl_iconified_set(Ecore_Evas *ee, int iconify)
803 LOGFN(__FILE__, __LINE__, __FUNCTION__);
806 if (ee->prop.iconified == iconify) return;
807 ee->prop.iconified = iconify;
808 /* FIXME: Implement this in Wayland someshow */
812 _ecore_evas_wl_maximized_set(Ecore_Evas *ee, int max)
814 LOGFN(__FILE__, __LINE__, __FUNCTION__);
817 if (ee->prop.maximized == max) return;
818 ee->prop.maximized = max;
819 /* FIXME: Implement this. Support is in Wayland now */
823 _ecore_evas_wl_fullscreen_set(Ecore_Evas *ee, int full __UNUSED__)
825 LOGFN(__FILE__, __LINE__, __FUNCTION__);
827 if ((!ee) || (!ee->visible)) return;
828 if (!ee->engine.wl.shell_surface) return;
829 wl_shell_surface_set_fullscreen(ee->engine.wl.shell_surface);
833 _ecore_evas_wl_render(Ecore_Evas *ee)
839 evas_norender(ee->evas);
842 Eina_List *ll = NULL, *updates = NULL;
843 Ecore_Evas *ee2 = NULL;
845 if (ee->func.fn_pre_render) ee->func.fn_pre_render(ee);
847 EINA_LIST_FOREACH(ee->sub_ecore_evas, ll, ee2)
849 if (ee2->func.fn_pre_render) ee2->func.fn_pre_render(ee2);
850 if (ee2->engine.func->fn_render)
851 rend |= ee2->engine.func->fn_render(ee2);
852 if (ee2->func.fn_post_render) ee2->func.fn_post_render(ee2);
855 if ((updates = evas_render_updates(ee->evas)))
860 EINA_LIST_FOREACH(updates, l, r)
862 if (ee->engine.wl.buffer)
863 wl_buffer_damage(ee->engine.wl.buffer,
864 r->x, r->y, r->w, r->h);
866 if (ee->engine.wl.surface)
867 wl_surface_damage(ee->engine.wl.surface,
868 r->x, r->y, r->w, r->h);
871 evas_render_updates_free(updates);
872 _ecore_evas_idle_timeout_update(ee);
878 if (ee->func.fn_post_render) ee->func.fn_post_render(ee);
885 _ecore_evas_wl_screen_geometry_get(const Ecore_Evas *ee __UNUSED__, int *x, int *y, int *w, int *h)
887 LOGFN(__FILE__, __LINE__, __FUNCTION__);
891 ecore_wl_screen_size_get(w, h);
895 _ecore_evas_wl_event_mouse_in(void *data __UNUSED__, int type __UNUSED__, void *event)
898 Ecore_Wl_Event_Mouse_In *ev;
900 LOGFN(__FILE__, __LINE__, __FUNCTION__);
903 ee = ecore_event_window_match(ev->window);
904 if ((!ee) || (ee->ignore_events)) return ECORE_CALLBACK_PASS_ON;
905 if (ev->window != ee->prop.window) return ECORE_CALLBACK_PASS_ON;
906 if (ee->func.fn_mouse_in) ee->func.fn_mouse_in(ee);
907 ecore_event_evas_modifier_lock_update(ee->evas, ev->modifiers);
908 evas_event_feed_mouse_in(ee->evas, ev->time, NULL);
909 _ecore_evas_mouse_move_process(ee, ev->x, ev->y, ev->time);
910 return ECORE_CALLBACK_PASS_ON;
914 _ecore_evas_wl_event_mouse_out(void *data __UNUSED__, int type __UNUSED__, void *event)
917 Ecore_Wl_Event_Mouse_Out *ev;
919 LOGFN(__FILE__, __LINE__, __FUNCTION__);
922 ee = ecore_event_window_match(ev->window);
923 if ((!ee) || (ee->ignore_events)) return ECORE_CALLBACK_PASS_ON;
924 if (ev->window != ee->prop.window) return ECORE_CALLBACK_PASS_ON;
925 ecore_event_evas_modifier_lock_update(ee->evas, ev->modifiers);
926 _ecore_evas_mouse_move_process(ee, ev->x, ev->y, ev->time);
927 evas_event_feed_mouse_out(ee->evas, ev->time, NULL);
928 if (ee->func.fn_mouse_out) ee->func.fn_mouse_out(ee);
929 if (ee->prop.cursor.object) evas_object_hide(ee->prop.cursor.object);
930 return ECORE_CALLBACK_PASS_ON;
934 _ecore_evas_wl_event_focus_in(void *data __UNUSED__, int type __UNUSED__, void *event)
937 Ecore_Wl_Event_Focus_In *ev;
939 LOGFN(__FILE__, __LINE__, __FUNCTION__);
942 ee = ecore_event_window_match(ev->window);
943 if ((!ee) || (ee->ignore_events)) return ECORE_CALLBACK_PASS_ON;
944 if (ev->window != ee->prop.window) return ECORE_CALLBACK_PASS_ON;
945 ee->prop.focused = 1;
946 evas_focus_in(ee->evas);
947 if (ee->func.fn_focus_in) ee->func.fn_focus_in(ee);
948 return ECORE_CALLBACK_PASS_ON;
952 _ecore_evas_wl_event_focus_out(void *data __UNUSED__, int type __UNUSED__, void *event)
955 Ecore_Wl_Event_Focus_Out *ev;
957 LOGFN(__FILE__, __LINE__, __FUNCTION__);
960 ee = ecore_event_window_match(ev->window);
961 if ((!ee) || (ee->ignore_events)) return ECORE_CALLBACK_PASS_ON;
962 if (ev->window != ee->prop.window) return ECORE_CALLBACK_PASS_ON;
963 evas_focus_out(ee->evas);
964 ee->prop.focused = 0;
965 if (ee->func.fn_focus_out) ee->func.fn_focus_out(ee);
966 return ECORE_CALLBACK_PASS_ON;
970 _ecore_evas_wl_handle_configure(void *data, struct wl_shell_surface *shell_surface, uint32_t timestamp __UNUSED__, uint32_t edges __UNUSED__, int32_t width, int32_t height)
974 /* NB: Trap to prevent compositor from crashing */
975 if ((width <= 0) || (height <= 0)) return;
977 if (!(ee = data)) return;
979 if ((shell_surface) && (ee->engine.wl.shell_surface))
981 if (ee->engine.wl.shell_surface != shell_surface) return;
982 ecore_evas_resize(ee, width, height);
987 _ecore_evas_wl_handle_popup_done(void *data __UNUSED__, struct wl_shell_surface *shell_surface __UNUSED__)
993 _ecore_evas_wl_buffer_new(Ecore_Evas *ee, void **dest)
996 static unsigned int format;
998 int fd = -1, stride = 0, size = 0;
1001 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1003 if (dest) *dest = NULL;
1004 if (!(shm = ecore_wl_shm_get())) return;
1005 if (!format) format = ecore_wl_format_get();
1007 strcpy(tmp, "/tmp/ecore-wayland_shm-XXXXXX");
1008 if ((fd = mkstemp(tmp)) < 0)
1010 ERR("Could not create temporary file.");
1014 stride = (ee->w * sizeof(int));
1015 size = (stride * ee->h);
1016 if (ftruncate(fd, size) < 0)
1018 ERR("Could not truncate temporary file.");
1023 ret = mmap(NULL, size, (PROT_READ | PROT_WRITE), MAP_SHARED, fd, 0);
1026 if (ret == MAP_FAILED)
1028 ERR("mmap of temporary file failed.");
1033 if (dest) *dest = ret;
1035 ee->engine.wl.buffer =
1036 wl_shm_create_buffer(ecore_wl_shm_get(), fd, ee->w, ee->h, stride, format);
1042 _ecore_evas_wl_smart_init(void)
1044 if (_ecore_evas_wl_smart) return;
1046 static const Evas_Smart_Class sc =
1048 "ecore_evas_wl_frame", EVAS_SMART_CLASS_VERSION,
1049 _ecore_evas_wl_smart_add,
1050 _ecore_evas_wl_smart_del,
1052 _ecore_evas_wl_smart_resize,
1053 _ecore_evas_wl_smart_show,
1054 _ecore_evas_wl_smart_hide,
1055 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
1057 _ecore_evas_wl_smart = evas_smart_class_new(&sc);
1062 _ecore_evas_wl_smart_add(Evas_Object *obj)
1064 EE_Wl_Smart_Data *sd;
1067 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1069 if (!(sd = calloc(1, sizeof(EE_Wl_Smart_Data)))) return;
1071 evas = evas_object_evas_get(obj);
1078 sd->frame = evas_object_rectangle_add(evas);
1079 evas_object_is_frame_object_set(sd->frame, EINA_TRUE);
1080 evas_object_color_set(sd->frame, 249, 249, 249, 255);
1081 evas_object_smart_member_add(sd->frame, obj);
1083 sd->text = evas_object_text_add(evas);
1084 evas_object_color_set(sd->text, 0, 0, 0, 255);
1085 evas_object_text_style_set(sd->text, EVAS_TEXT_STYLE_PLAIN);
1086 evas_object_text_font_set(sd->text, "Sans", 10);
1087 evas_object_text_text_set(sd->text, "Smart Test");
1089 evas_object_smart_data_set(obj, sd);
1093 _ecore_evas_wl_smart_del(Evas_Object *obj)
1095 EE_Wl_Smart_Data *sd;
1097 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1099 if (!(sd = evas_object_smart_data_get(obj))) return;
1100 evas_object_del(sd->text);
1101 evas_object_del(sd->frame);
1106 _ecore_evas_wl_smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
1108 EE_Wl_Smart_Data *sd;
1110 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1112 if (!(sd = evas_object_smart_data_get(obj))) return;
1113 if ((sd->w == w) && (sd->h == h)) return;
1116 evas_object_resize(sd->frame, w, h);
1120 _ecore_evas_wl_smart_show(Evas_Object *obj)
1122 EE_Wl_Smart_Data *sd;
1124 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1126 if (!(sd = evas_object_smart_data_get(obj))) return;
1127 evas_object_show(sd->frame);
1128 evas_object_show(sd->text);
1132 _ecore_evas_wl_smart_hide(Evas_Object *obj)
1134 EE_Wl_Smart_Data *sd;
1136 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1138 if (!(sd = evas_object_smart_data_get(obj))) return;
1139 evas_object_hide(sd->text);
1140 evas_object_hide(sd->frame);
1143 static Evas_Object *
1144 _ecore_evas_wl_frame_add(Evas *evas)
1146 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1148 _ecore_evas_wl_smart_init();
1149 return evas_object_smart_add(evas, _ecore_evas_wl_smart);
1153 _ecore_evas_wayland_shm_resize(Ecore_Evas *ee, int location)
1155 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1157 if ((!ee) || (!ee->engine.wl.shell_surface)) return;
1158 wl_shell_surface_resize(ee->engine.wl.shell_surface,
1159 ecore_wl_input_device_get(),
1160 ecore_wl_input_timestamp_get(), location);
1164 _ecore_evas_wayland_shm_drag_start(Ecore_Evas *ee, Ecore_Evas *drag_ee, void *source)
1166 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1168 if ((!ee) || (!ee->engine.wl.surface)) return;
1169 if ((!source) || (!drag_ee)) return;
1170 ecore_wl_drag_start(source, ee->engine.wl.surface, drag_ee->engine.wl.buffer);
1175 ecore_evas_wayland_shm_new(const char *disp_name __UNUSED__, int x __UNUSED__, int y __UNUSED__, int w __UNUSED__, int h __UNUSED__, int frame __UNUSED__)