5 #include "ecore_evas_private.h"
6 #include "Ecore_Evas.h"
9 typedef struct _EE_Wl_Smart_Data EE_Wl_Smart_Data;
10 struct _EE_Wl_Smart_Data
14 Evas_Coord x, y, w, h;
17 static Evas_Smart *_ecore_evas_wl_common_smart = NULL;
21 static int _ecore_evas_wl_init_count = 0;
22 static Ecore_Event_Handler *_ecore_evas_wl_event_hdls[5];
25 _ecore_evas_wl_common_cb_mouse_in(void *data __UNUSED__, int type __UNUSED__, void *event)
28 Ecore_Wl_Event_Mouse_In *ev;
31 ee = ecore_event_window_match(ev->window);
32 if ((!ee) || (ee->ignore_events)) return ECORE_CALLBACK_PASS_ON;
33 if (ev->window != ee->prop.window) return ECORE_CALLBACK_PASS_ON;
36 if (ee->func.fn_mouse_in) ee->func.fn_mouse_in(ee);
37 ecore_event_evas_modifier_lock_update(ee->evas, ev->modifiers);
38 evas_event_feed_mouse_in(ee->evas, ev->timestamp, NULL);
41 return ECORE_CALLBACK_PASS_ON;
45 _ecore_evas_wl_common_cb_mouse_out(void *data __UNUSED__, int type __UNUSED__, void *event)
48 Ecore_Wl_Event_Mouse_Out *ev;
51 ee = ecore_event_window_match(ev->window);
52 if ((!ee) || (ee->ignore_events)) return ECORE_CALLBACK_PASS_ON;
53 if (ev->window != ee->prop.window) return ECORE_CALLBACK_PASS_ON;
56 ecore_event_evas_modifier_lock_update(ee->evas, ev->modifiers);
57 evas_event_feed_mouse_out(ee->evas, ev->timestamp, NULL);
58 if (ee->func.fn_mouse_out) ee->func.fn_mouse_out(ee);
59 if (ee->prop.cursor.object) evas_object_hide(ee->prop.cursor.object);
62 return ECORE_CALLBACK_PASS_ON;
66 _ecore_evas_wl_common_cb_focus_in(void *data __UNUSED__, int type __UNUSED__, void *event)
69 Ecore_Wl_Event_Focus_In *ev;
72 ee = ecore_event_window_match(ev->win);
73 if ((!ee) || (ee->ignore_events)) return ECORE_CALLBACK_PASS_ON;
74 if (ev->win != ee->prop.window) return ECORE_CALLBACK_PASS_ON;
76 evas_focus_in(ee->evas);
77 if (ee->func.fn_focus_in) ee->func.fn_focus_in(ee);
78 return ECORE_CALLBACK_PASS_ON;
82 _ecore_evas_wl_common_cb_focus_out(void *data __UNUSED__, int type __UNUSED__, void *event)
85 Ecore_Wl_Event_Focus_In *ev;
88 ee = ecore_event_window_match(ev->win);
89 if ((!ee) || (ee->ignore_events)) return ECORE_CALLBACK_PASS_ON;
90 if (ev->win != ee->prop.window) return ECORE_CALLBACK_PASS_ON;
91 evas_focus_out(ee->evas);
93 if (ee->func.fn_focus_out) ee->func.fn_focus_out(ee);
94 return ECORE_CALLBACK_PASS_ON;
98 _ecore_evas_wl_common_cb_window_configure(void *data __UNUSED__, int type __UNUSED__, void *event)
101 Ecore_Wl_Event_Window_Configure *ev;
105 ee = ecore_event_window_match(ev->win);
106 if (!ee) return ECORE_CALLBACK_PASS_ON;
107 if (ev->win != ee->prop.window) return ECORE_CALLBACK_PASS_ON;
109 if (ee->prop.fullscreen)
111 _ecore_evas_wl_common_move(ee, ev->x, ev->y);
112 ee->engine.func->fn_resize(ee, ev->w, ev->h);
114 return ECORE_CALLBACK_PASS_ON;
117 if ((ee->x != ev->x) || (ee->y != ev->y))
121 if (ee->func.fn_move) ee->func.fn_move(ee);
127 if ((ee->prop.maximized) || (!ee->prop.fullscreen))
131 evas_output_framespace_get(ee->evas, NULL, NULL, &fw, &fh);
136 if (ee->prop.min.w > nw) nw = ee->prop.min.w;
137 else if (nw > ee->prop.max.w) nw = ee->prop.max.w;
138 if (ee->prop.min.h > nh) nh = ee->prop.min.h;
139 else if (nh > ee->prop.max.h) nh = ee->prop.max.h;
141 if ((ee->w != nw) || (ee->h != nh))
145 if (ee->func.fn_resize) ee->func.fn_resize(ee);
148 return ECORE_CALLBACK_PASS_ON;
152 _ecore_evas_wl_common_init(void)
154 if (++_ecore_evas_wl_init_count != 1)
155 return _ecore_evas_wl_init_count;
157 _ecore_evas_wl_event_hdls[0] =
158 ecore_event_handler_add(ECORE_WL_EVENT_MOUSE_IN,
159 _ecore_evas_wl_common_cb_mouse_in, NULL);
160 _ecore_evas_wl_event_hdls[1] =
161 ecore_event_handler_add(ECORE_WL_EVENT_MOUSE_OUT,
162 _ecore_evas_wl_common_cb_mouse_out, NULL);
163 _ecore_evas_wl_event_hdls[2] =
164 ecore_event_handler_add(ECORE_WL_EVENT_FOCUS_IN,
165 _ecore_evas_wl_common_cb_focus_in, NULL);
166 _ecore_evas_wl_event_hdls[3] =
167 ecore_event_handler_add(ECORE_WL_EVENT_FOCUS_OUT,
168 _ecore_evas_wl_common_cb_focus_out, NULL);
169 _ecore_evas_wl_event_hdls[4] =
170 ecore_event_handler_add(ECORE_WL_EVENT_WINDOW_CONFIGURE,
171 _ecore_evas_wl_common_cb_window_configure, NULL);
173 ecore_event_evas_init();
175 return _ecore_evas_wl_init_count;
179 _ecore_evas_wl_common_shutdown(void)
183 if (--_ecore_evas_wl_init_count != 0)
184 return _ecore_evas_wl_init_count;
186 for (i = 0; i < sizeof(_ecore_evas_wl_event_hdls) / sizeof(Ecore_Event_Handler *); i++)
188 if (_ecore_evas_wl_event_hdls[i])
189 ecore_event_handler_del(_ecore_evas_wl_event_hdls[i]);
192 ecore_event_evas_shutdown();
194 return _ecore_evas_wl_init_count;
198 _ecore_evas_wl_common_pre_free(Ecore_Evas *ee)
201 if (ee->engine.wl.frame) evas_object_del(ee->engine.wl.frame);
205 _ecore_evas_wl_common_free(Ecore_Evas *ee)
207 if (ee->engine.wl.win) ecore_wl_window_free(ee->engine.wl.win);
208 ee->engine.wl.win = NULL;
210 ecore_event_window_unregister(ee->prop.window);
211 ecore_evas_input_event_unregister(ee);
213 _ecore_evas_wl_common_shutdown();
218 _ecore_evas_wl_common_resize(Ecore_Evas *ee, int w, int h)
226 if (!ee->prop.fullscreen)
230 if (ee->prop.min.w > w) w = ee->prop.min.w;
231 else if (w > ee->prop.max.w) w = ee->prop.max.w;
232 if (ee->prop.min.h > h) h = ee->prop.min.h;
233 else if (h > ee->prop.max.h) h = ee->prop.max.h;
235 evas_output_framespace_get(ee->evas, NULL, NULL, &fw, &fh);
240 if ((ee->w != w) || (ee->h != h))
245 if ((ee->rotation == 90) || (ee->rotation == 270))
247 evas_output_size_set(ee->evas, h, w);
248 evas_output_viewport_set(ee->evas, 0, 0, h, w);
252 evas_output_size_set(ee->evas, w, h);
253 evas_output_viewport_set(ee->evas, 0, 0, w, h);
256 if (ee->prop.avoid_damage)
260 pdam = ecore_evas_avoid_damage_get(ee);
261 ecore_evas_avoid_damage_set(ee, 0);
262 ecore_evas_avoid_damage_set(ee, pdam);
265 if (ee->engine.wl.frame)
266 evas_object_resize(ee->engine.wl.frame, w, h);
271 _ecore_evas_wl_common_callback_resize_set(Ecore_Evas *ee, void (*func)(Ecore_Evas *ee))
274 ee->func.fn_resize = func;
278 _ecore_evas_wl_common_callback_move_set(Ecore_Evas *ee, void (*func)(Ecore_Evas *ee))
281 ee->func.fn_move = func;
285 _ecore_evas_wl_common_callback_delete_request_set(Ecore_Evas *ee, void (*func)(Ecore_Evas *ee))
288 ee->func.fn_delete_request = func;
292 _ecore_evas_wl_common_callback_focus_in_set(Ecore_Evas *ee, void (*func)(Ecore_Evas *ee))
295 ee->func.fn_focus_in = func;
299 _ecore_evas_wl_common_callback_focus_out_set(Ecore_Evas *ee, void (*func)(Ecore_Evas *ee))
302 ee->func.fn_focus_out = func;
306 _ecore_evas_wl_common_callback_mouse_in_set(Ecore_Evas *ee, void (*func)(Ecore_Evas *ee))
309 ee->func.fn_mouse_in = func;
313 _ecore_evas_wl_common_callback_mouse_out_set(Ecore_Evas *ee, void (*func)(Ecore_Evas *ee))
316 ee->func.fn_mouse_out = func;
320 _ecore_evas_wl_common_move(Ecore_Evas *ee, int x, int y)
327 if ((ee->x != x) || (ee->y != y))
331 if (ee->engine.wl.win)
332 ecore_wl_window_update_location(ee->engine.wl.win, x, y);
333 if (ee->func.fn_move) ee->func.fn_move(ee);
338 _ecore_evas_wl_common_smart_add(Evas_Object *obj)
340 EE_Wl_Smart_Data *sd;
343 if (!(sd = calloc(1, sizeof(EE_Wl_Smart_Data)))) return;
345 evas = evas_object_evas_get(obj);
352 sd->frame = evas_object_rectangle_add(evas);
353 evas_object_is_frame_object_set(sd->frame, EINA_TRUE);
354 evas_object_color_set(sd->frame, 249, 249, 249, 255);
355 evas_object_smart_member_add(sd->frame, obj);
357 sd->text = evas_object_text_add(evas);
358 evas_object_color_set(sd->text, 0, 0, 0, 255);
359 evas_object_text_style_set(sd->text, EVAS_TEXT_STYLE_PLAIN);
360 evas_object_text_font_set(sd->text, "Sans", 10);
361 evas_object_text_text_set(sd->text, "Smart Test");
363 evas_object_smart_data_set(obj, sd);
367 _ecore_evas_wl_common_smart_del(Evas_Object *obj)
369 EE_Wl_Smart_Data *sd;
371 if (!(sd = evas_object_smart_data_get(obj))) return;
372 evas_object_del(sd->text);
373 evas_object_del(sd->frame);
378 _ecore_evas_wl_common_smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
380 EE_Wl_Smart_Data *sd;
382 if (!(sd = evas_object_smart_data_get(obj))) return;
383 if ((sd->w == w) && (sd->h == h)) return;
386 evas_object_resize(sd->frame, w, h);
390 _ecore_evas_wl_common_smart_show(Evas_Object *obj)
392 EE_Wl_Smart_Data *sd;
394 if (!(sd = evas_object_smart_data_get(obj))) return;
395 evas_object_show(sd->frame);
396 evas_object_show(sd->text);
400 _ecore_evas_wl_common_smart_hide(Evas_Object *obj)
402 EE_Wl_Smart_Data *sd;
404 if (!(sd = evas_object_smart_data_get(obj))) return;
405 evas_object_hide(sd->text);
406 evas_object_hide(sd->frame);
410 _ecore_evas_wl_common_smart_init(void)
412 if (_ecore_evas_wl_common_smart) return;
414 static const Evas_Smart_Class sc =
416 "ecore_evas_wl_frame", EVAS_SMART_CLASS_VERSION,
417 _ecore_evas_wl_common_smart_add,
418 _ecore_evas_wl_common_smart_del,
420 _ecore_evas_wl_common_smart_resize,
421 _ecore_evas_wl_common_smart_show,
422 _ecore_evas_wl_common_smart_hide,
423 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
425 _ecore_evas_wl_common_smart = evas_smart_class_new(&sc);
430 _ecore_evas_wl_common_frame_add(Evas *evas)
432 _ecore_evas_wl_common_smart_init();
433 return evas_object_smart_add(evas, _ecore_evas_wl_common_smart);
437 _ecore_evas_wl_common_raise(Ecore_Evas *ee)
439 if ((!ee) || (!ee->visible)) return;
440 ecore_wl_window_raise(ee->engine.wl.win);
444 _ecore_evas_wl_common_title_set(Ecore_Evas *ee, const char *title)
447 if (ee->prop.title) free(ee->prop.title);
448 ee->prop.title = NULL;
449 if (title) ee->prop.title = strdup(title);
450 if ((ee->prop.draw_frame) && (ee->engine.wl.frame))
452 EE_Wl_Smart_Data *sd;
454 if (!(sd = evas_object_smart_data_get(ee->engine.wl.frame))) return;
455 evas_object_text_text_set(sd->text, ee->prop.title);
458 if ((ee->prop.title) && (ee->engine.wl.win->shell_surface))
459 wl_shell_surface_set_title(ee->engine.wl.win->shell_surface,
464 _ecore_evas_wl_common_name_class_set(Ecore_Evas *ee, const char *n, const char *c)
467 if (ee->prop.name) free(ee->prop.name);
468 if (ee->prop.clas) free(ee->prop.clas);
469 ee->prop.name = NULL;
470 ee->prop.clas = NULL;
471 if (n) ee->prop.name = strdup(n);
472 if (c) ee->prop.clas = strdup(c);
474 if ((ee->prop.clas) && (ee->engine.wl.win->shell_surface))
475 wl_shell_surface_set_class(ee->engine.wl.win->shell_surface,
480 _ecore_evas_wl_common_size_min_set(Ecore_Evas *ee, int w, int h)
485 if ((ee->prop.min.w == w) && (ee->prop.min.h == h)) return;
491 _ecore_evas_wl_common_size_max_set(Ecore_Evas *ee, int w, int h)
496 if ((ee->prop.max.w == w) && (ee->prop.max.h == h)) return;
502 _ecore_evas_wl_common_size_base_set(Ecore_Evas *ee, int w, int h)
507 if ((ee->prop.base.w == w) && (ee->prop.base.h == h)) return;
513 _ecore_evas_wl_common_size_step_set(Ecore_Evas *ee, int w, int h)
518 if ((ee->prop.step.w == w) && (ee->prop.step.h == h)) return;
524 _ecore_evas_wl_common_layer_set(Ecore_Evas *ee, int layer)
527 if (ee->prop.layer == layer) return;
528 if (layer < 1) layer = 1;
529 else if (layer > 255) layer = 255;
530 ee->prop.layer = layer;
534 _ecore_evas_wl_common_iconified_set(Ecore_Evas *ee, int iconify)
537 if (ee->prop.iconified == iconify) return;
538 ee->prop.iconified = iconify;
539 /* FIXME: Implement this in Wayland someshow */
543 _ecore_evas_wl_common_maximized_set(Ecore_Evas *ee, int max)
546 if (ee->prop.maximized == max) return;
547 ee->prop.maximized = max;
548 ecore_wl_window_maximized_set(ee->engine.wl.win, max);
552 _ecore_evas_wl_common_fullscreen_set(Ecore_Evas *ee, int full)
555 if (ee->prop.fullscreen == full) return;
556 ee->prop.fullscreen = full;
557 ecore_wl_window_fullscreen_set(ee->engine.wl.win, full);
561 _ecore_evas_wl_common_ignore_events_set(Ecore_Evas *ee, int ignore)
564 ee->ignore_events = ignore;
565 /* NB: Hmmm, may need to pass this to ecore_wl_window in the future */
569 _ecore_evas_wl_common_pre_render(Ecore_Evas *ee)
572 Eina_List *ll = NULL;
573 Ecore_Evas *ee2 = NULL;
575 if (ee->func.fn_pre_render) ee->func.fn_pre_render(ee);
577 EINA_LIST_FOREACH(ee->sub_ecore_evas, ll, ee2)
579 if (ee2->func.fn_pre_render) ee2->func.fn_pre_render(ee2);
580 if (ee2->engine.func->fn_render)
581 rend |= ee2->engine.func->fn_render(ee2);
582 if (ee2->func.fn_post_render) ee2->func.fn_post_render(ee2);
589 _ecore_evas_wl_common_render_updates(Ecore_Evas *ee)
592 Eina_List *updates = NULL;
594 if ((updates = evas_render_updates(ee->evas)))
599 EINA_LIST_FOREACH(updates, l, r)
600 ecore_wl_window_damage(ee->engine.wl.win,
601 r->x, r->y, r->w, r->h);
605 evas_render_updates_free(updates);
613 _ecore_evas_wl_common_post_render(Ecore_Evas *ee)
615 _ecore_evas_idle_timeout_update(ee);
616 if (ee->func.fn_post_render) ee->func.fn_post_render(ee);
620 _ecore_evas_wl_common_render(Ecore_Evas *ee)
627 evas_norender(ee->evas);
631 rend = _ecore_evas_wl_common_pre_render(ee);
632 rend |= _ecore_evas_wl_common_render_updates(ee);
633 _ecore_evas_wl_common_post_render(ee);
639 _ecore_evas_wl_common_screen_geometry_get(const Ecore_Evas *ee __UNUSED__, int *x, int *y, int *w, int *h)
643 ecore_wl_screen_size_get(w, h);
647 _ecore_evas_wl_common_screen_dpi_get(const Ecore_Evas *ee __UNUSED__, int *xdpi, int *ydpi)
653 /* FIXME: Ideally this needs to get the DPI from a specific screen */
654 dpi = ecore_wl_dpi_get();
655 if (xdpi) *xdpi = dpi;
656 if (ydpi) *ydpi = dpi;